private void ShowSampleItems_Click(object sender, EventArgs e) { // create some sample items; MyMap.MapElements.Clear(); MyMap.Layers.Clear(); var bounds = new List<LocationRectangle>(); foreach (var area in DataManager.SampleAreas) { var shape = new MapPolygon(); foreach (var parts in area.Split(' ').Select(cord => cord.Split(','))) { shape.Path.Add(new GeoCoordinate(double.Parse(parts[1], ci), double.Parse(parts[0], ci))); } shape.StrokeThickness = 3; shape.StrokeColor = Colors.Blue; shape.FillColor = Color.FromArgb((byte)0x20, shape.StrokeColor.R, shape.StrokeColor.G, shape.StrokeColor.B); bounds.Add(LocationRectangle.CreateBoundingRectangle(shape.Path)); MyMap.MapElements.Add(shape); } var rect = new LocationRectangle(bounds.Max(b => b.North), bounds.Min(b => b.West), bounds.Min(b => b.South), bounds.Max(b => b.East)); MyMap.SetView(rect); // show all Items var itemsLayer = new MapLayer(); foreach (var item in DataManager.SampleItems) { DrawItem(item, "Ulm", itemsLayer); } MyMap.Layers.Add(itemsLayer); }
/// <summary> /// Called when the pinned locations change. /// </summary> private void OnPinnedLocationsChanged() { var itemsContainer = MapExtensions.GetChildren(LayoutRoot).OfType <MapItemsControl>().ElementAt(0); itemsContainer.Items.Clear(); foreach (var loc in PinnedLocations) { itemsContainer.Items.Add(loc); } var coords = PinnedLocations.Select(loc => loc.Position) .Select(p => new GeoCoordinate(p.Latitude, p.Longitude)) .ToArray(); if (coords.Length == 1) { LayoutRoot.Center = coords[0]; Properties.BuildingsLevel = PinnedLocations[0].Floor ?? 0; } else if (coords.Length > 1) { LayoutRoot.SetView(LocationRectangle.CreateBoundingRectangle(coords)); Properties.BuildingsLevel = PinnedLocations[0].Floor ?? 0; } }
private void DisplayRoute(TripMessage tripMessage) { RouteMap.MapElements.Clear(); if (tripMessage.Trip.BoundingBoxBottomRight != null && tripMessage.Trip.BoundingBoxTopLeft != null) { RouteMap.SetView(LocationRectangle.CreateBoundingRectangle(tripMessage.Trip.BoundingBoxBottomRight.GeoCoordinate, tripMessage.Trip.BoundingBoxTopLeft.GeoCoordinate)); } foreach (TripRoute tripRoute in tripMessage.Trip.TripRoutes) { if (tripRoute.Coordinates.Count() >= 2) { MapPolyline route = new MapPolyline(); route.StrokeColor = ThemeColourConverter.GetBrushFromHex(tripRoute.Colour).Color; route.StrokeThickness = 9; MapPolyline routeBlack = new MapPolyline(); routeBlack.StrokeColor = ThemeColourConverter.GetBrushFromHex(ThemeColourConverter.Black).Color; routeBlack.StrokeThickness = 11; foreach (Coordinate coordinate in tripRoute.Coordinates) { route.Path.Add(coordinate.GeoCoordinate); routeBlack.Path.Add(coordinate.GeoCoordinate); } RouteMap.MapElements.Add(routeBlack); RouteMap.MapElements.Add(route); } } }
public static LocationRectangle SetCenter(LocationRectangle rect, GeoCoordinate center) { double north, west, south, east; if (rect.North - center.Latitude < center.Latitude - rect.South) { north = center.Latitude + center.Latitude - rect.South; south = rect.South; } else { north = rect.North; south = center.Latitude - (rect.North - center.Latitude); } if (rect.East - center.Longitude < center.Longitude - rect.West) { west = rect.West; east = center.Longitude + (center.Longitude - rect.West); } else { west = center.Longitude - (rect.East - center.Longitude); east = rect.East; } return(new LocationRectangle(north, west, south, east)); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { var viewModel = new CarViewModel(); await viewModel.InitializeData(); this.DataContext = viewModel; MapLayer layer = new MapLayer(); var pts = new List <GeoCoordinate>(); foreach (var item in viewModel.Cars) { Pushpin pushpin = new Pushpin(); pushpin.GeoCoordinate = new System.Device.Location.GeoCoordinate(item.latitude, item.longitude); MapOverlay overlay = new MapOverlay(); overlay.Content = pushpin; overlay.GeoCoordinate = new System.Device.Location.GeoCoordinate(item.latitude, item.longitude); layer.Add(overlay); pts.Add(new System.Device.Location.GeoCoordinate(item.latitude, item.longitude)); } map.Layers.Clear(); map.Layers.Add(layer); map.SetView(LocationRectangle.CreateBoundingRectangle(pts)); base.OnNavigatedTo(e); }
public static LocationRectangle CreateBoundingRectangle(this Map map) { var geoCoordinates = (from layer in map.Layers from mapo in layer where mapo.GeoCoordinate != null select mapo.GeoCoordinate).ToList(); foreach (var mapElement in map.MapElements) { if (mapElement as MapPolyline != null) { var element = mapElement as MapPolyline; geoCoordinates.AddRange(element.Path); } if (mapElement as MapPolygon != null) { var element = mapElement as MapPolygon; geoCoordinates.AddRange(element.Path); } } geoCoordinates.AddRange(from dependencyObject in Microsoft.Phone.Maps.Toolkit.MapExtensions.GetChildren(map) where dependencyObject as Pushpin != null select(dependencyObject as Pushpin).GeoCoordinate); if (!geoCoordinates.Any()) { geoCoordinates.Add(new GeoCoordinate(-34.77828, -58.152802)); geoCoordinates.Add(new GeoCoordinate(-34.498069, -58.726151)); } return(LocationRectangle.CreateBoundingRectangle(geoCoordinates)); }
/// <summary> /// Finish initializations after setting the viewmodel /// </summary> /// <returns></returns> private async Task InitializeFromViewModel() { this.DataContext = this.ViewModel; ProgressIndicatorHelper.Instance.Push(LoadingEnum.Stops); //PIHelper.Push("Getting stops..."); //var ls = await TransitInfo.GetStopsOfRoute(this.ViewModel.Context); if (!ViewModel.Context.Stop_Ids.Any(id => !AppSettings.KnownStops.Value.ContainsKey(id)) || TransitLoader.InternetAvailable()) { await ViewModel.GetStopsOfRoute(); } ProgressIndicatorHelper.Instance.Remove(LoadingEnum.Stops); // Center the map if (this.ViewModel.Stops.Count > 0) { this.MapItems.ItemsSource = this.ViewModel.Stops; this.startup = false; this.ResultsMap.SetView(LocationRectangle.CreateBoundingRectangle(this.ViewModel.Stops.Select(s => s.Location))); } else { this.startup = false; } }
void FitToView() { LocationRectangle setRect = null; if (selected_shape == "Polygon" && (poly != null)) { Debug.WriteLine("Fitting polygon into the view"); setRect = LocationRectangle.CreateBoundingRectangle(poly.Path); } else if (selected_shape == "Polyline" && (polyline != null)) { double north = 0; double west = 0; double south = 0; double east = 0; north = south = polyline.Path[0].Latitude; west = east = polyline.Path[0].Longitude; foreach (var p in polyline.Path.Skip(1)) { if (north < p.Latitude) { north = p.Latitude; } if (west > p.Longitude) { west = p.Longitude; } if (south > p.Latitude) { south = p.Latitude; } if (east < p.Longitude) { east = p.Longitude; } } setRect = new LocationRectangle(north, west, south, east); } else if (selected_shape == "Markers" && (markerLayer != null)) { Debug.WriteLine("Fitting: " + markerLayer.Count() + " markers into the view"); GeoCoordinate[] geoArr = new GeoCoordinate[markerLayer.Count()]; for (var p = 0; p < markerLayer.Count(); p++) { geoArr[p] = markerLayer[p].GeoCoordinate; } setRect = LocationRectangle.CreateBoundingRectangle(geoArr); } if (setRect != null) { map1.SetView(setRect); } }
void MoveToRegion(MapSpan span, MapAnimationKind animation = MapAnimationKind.Parabolic) { // FIXME var center = new GeoCoordinate(span.Center.Latitude, span.Center.Longitude); var location = new LocationRectangle(center, span.LongitudeDegrees, span.LatitudeDegrees); Control.SetView(location, animation); }
/// <summary> /// Will set view in the map to an area that will display all the stores in the map /// </summary> private void MapFlightToSeattle() { LocationRectangle locationRectangle; locationRectangle = LocationRectangle.CreateBoundingRectangle(from store in this.mainViewModel.StoreList select store.GeoCoordinate); this.Map.SetView(locationRectangle, new Thickness(20, 20, 20, 20)); }
private void UpdateMap(GeoCoordinate location) { Dispatcher.BeginInvoke(() => { marker.GeoCoordinate = location; routeLine.Path.Add(location); mapControl.SetView(LocationRectangle.CreateBoundingRectangle(routeLine.Path)); }); }
public void CarregarDados(Int32 pLinhaId) { this.LayerPontosOnibus = new MapLayer(); this.ShapeRota = new MapPolyline(); App.LinhaSelecionada = LinhaFacade.Instance.ObterPorId(pLinhaId); #region Shape da linha var listaRotas = RotaFacade.Instance.ListarRotaPorLinha(App.LinhaSelecionada.Codigo); var CoordenadasRota = new GeoCoordinateCollection(); var listaCoordenadas = listaRotas.Select(rota => new GeoCoordinate(Convert.ToDouble(rota.Latitude), Convert.ToDouble(rota.Longitude))).ToList(); foreach (var item in listaCoordenadas) { CoordenadasRota.Add(item); } ShapeRota.StrokeColor = App.LinhaSelecionada.ObjetoCor; ShapeRota.StrokeThickness = 4; ShapeRota.Path = CoordenadasRota; LayoutRota = LocationRectangle.CreateBoundingRectangle(CoordenadasRota); #endregion #region Pontos da linha //Desenha os pontos da linha no layer var listaPontos = PontoFacade.Instance.ListarPontosPorLinha(App.LinhaSelecionada.Codigo); foreach (var ponto in listaPontos) { double latitude = 0, longitude = 0; Double.TryParse(ponto.Latitude, out latitude); Double.TryParse(ponto.Longitude, out longitude); var coordenada = new GeoCoordinate(latitude, longitude); var imgPontoOnibus = PinMaker.PontoDeOnibus(ponto) as Image; imgPontoOnibus.Tap += (sender, e) => { MessageBox.Show(ponto.Nome); }; var mapOver = new MapOverlay(); mapOver.GeoCoordinate = coordenada; mapOver.Content = imgPontoOnibus; mapOver.PositionOrigin = new Point(0.5, 1); LayerPontosOnibus.Add(mapOver); } #endregion if (CarregamentoCompleto != null) { CarregamentoCompleto(this, null); } }
/// <summary> /// Set view once map is loaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ResultsMap_Loaded(object sender, RoutedEventArgs e) { Microsoft.Phone.Maps.MapsSettings.ApplicationContext.ApplicationId = Util.MapApplicationID; Microsoft.Phone.Maps.MapsSettings.ApplicationContext.AuthenticationToken = Util.MapAuthenticationToken; System.Threading.Thread.Sleep(500); if (!this.startup && this.ViewModel != null && this.ViewModel.Stops.Count > 0) { this.ResultsMap.SetView(LocationRectangle.CreateBoundingRectangle(this.ViewModel.Stops.Select(s => s.Location))); } }
private void MapLoaded(object arg) { Microsoft.Phone.Maps.MapsSettings.ApplicationContext.ApplicationId = "3372500c-0f7b-4117-b085-3977a972844f"; Microsoft.Phone.Maps.MapsSettings.ApplicationContext.AuthenticationToken = "ybxfo_GnI9Y231Eykykl0A"; if (All.Count > 0) { MapBound = LocationRectangle.CreateBoundingRectangle( All.Select(m => new GeoCoordinate(m.Latitude.Value, m.Longitude.Value))); } }
public static LocationRectangle WidenBoundaries(LocationRectangle rect) { var center = rect.Center; double latUnit = 150.0 / App.Config.LatitudeDegreeDistance; double lonUnit = 150.0 / App.Config.LongitudeDegreeDistance; LocationRectangle widedRect = new LocationRectangle( north: Math.Max(rect.North, rect.Center.Latitude + latUnit), south: Math.Min(rect.South, rect.Center.Latitude - latUnit), east: Math.Max(rect.East, rect.Center.Longitude + lonUnit), west: Math.Min(rect.West, rect.Center.Longitude - lonUnit) ); return(widedRect); }
/// <summary> /// Center and zoom the map on location and the destination /// </summary> public void CenterAndZoom() { if (LocationTracker.Location != null && this.ViewModel != null) { this.ReZoomMap = false; this.TrackMap.SetView(LocationRectangle.CreateBoundingRectangle( LocationTracker.Location, this.ViewModel.Context.Location)); } else if (this.ViewModel != null) { this.TrackMap.SetView(LocationRectangle.CreateBoundingRectangle( this.ViewModel.Context.Location)); } }
/// <summary> /// /// </summary> /// <param name="track"></param> public void LoadTrackInMap(GeoCoordinateCollection track) { MapPolyline line = new MapPolyline(); line.StrokeColor = _miscFunctions.GetAccentColor(); line.StrokeThickness = 4; line.Path = track; LocationRectangle locRect = new LocationRectangle(track.Max((p) => p.Latitude), track.Min((p) => p.Longitude), track.Min((p) => p.Latitude), track.Max((p) => p.Longitude)); App.MyMap.MapElements.Add(line); App.MyMap.SetView(locRect); }
private void MyMap_Loaded(object sender, RoutedEventArgs e) { System.Threading.Thread.Sleep(500); var poiList = ViewModel.PointOfInterestList; if (poiList.Count > 0) { var bounds = new LocationRectangle( poiList.Max((p) => p.Latitude), poiList.Min((p) => p.Longitude), poiList.Min((p) => p.Latitude), poiList.Max((p) => p.Longitude)); MyMap.SetView(bounds); } }
private void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e) { if (e.Error == null) { Route MyRoute = e.Result; if (MyMapRoute != null) { //clear last route MyMap.RemoveRoute(MyMapRoute); } MyMapRoute = new MapRoute(MyRoute); MyMap.AddRoute(MyMapRoute); MyQuery.Dispose(); //set the map view to fit the route LocationRectangle locationRectangle = LocationRectangle.CreateBoundingRectangle(MyRoute.Geometry); this.MyMap.SetView(locationRectangle, new Thickness(10)); } }
/// <summary> /// set the map view to show all friends in the list /// </summary> private void SetProperMapZoomLevel() { //Find all located friends in the list List <Friend> temp = new List <Friend>(); foreach (var item in App.ViewModel.Friends) { if (item.isLocated()) { temp.Add(item); } } //including Me if (Me.isLocated()) { temp.Add(Me); } LocationRectangle locationRectangle = LocationRectangle.CreateBoundingRectangle(from Friend in temp select Friend.Geocoordinate); this.MyMap.SetView(locationRectangle, new Thickness(20)); }
void UpdateVisibleRegion() { if (!_firstZoomLevelChangeFired) { MoveToRegion(Element.LastMoveToRegion, MapAnimationKind.None); _firstZoomLevelChangeFired = true; return; } var center = new Position(Control.Center.Latitude, Control.Center.Longitude); var topLeft = Control.ConvertViewportPointToGeoCoordinate(new System.Windows.Point(0, 0)); var bottomRight = Control.ConvertViewportPointToGeoCoordinate(new System.Windows.Point(Control.ActualWidth, Control.ActualHeight)); if (topLeft == null || bottomRight == null) { return; } var boundingRegion = LocationRectangle.CreateBoundingRectangle(topLeft, bottomRight); var result = new MapSpan(center, boundingRegion.HeightInDegrees, boundingRegion.WidthInDegrees); Element.SetVisibleRegion(result); }
private void myMaps_ResolveCompleted(object sender, Microsoft.Phone.Maps.Controls.MapResolveCompletedEventArgs e) { if (AppManagement._flagStoryBoard == true || AppManagement._flagclickMarker == true) { AppManagement._flagStoryBoard = false; AppManagement._flagclickMarker = false; } else { if (checkNetworkConnection() == true) { if (StoryboardBottom.GetCurrentState() == ClockState.Active) { AppManagement._flagExitApp = true; StoryboardBottom.Stop(); } LocationRectangle rec = GetVisibleMapAre(myMaps); GetListNhaTro(rec.Southeast, rec.Northwest); //customIndeterminateProgressBar.IsIndeterminate = false; } } }
private void drawPath(DateTime date) { Map1.MapElements.Clear(); MapPolyline polygon = new MapPolyline(); //polygon.StrokeColor = ; polygon.StrokeThickness = 3; polygon.Path = new GeoCoordinateCollection(); List <string> coordinates = App.read(App.getFileName(App.LOC_LOG, date)); double maxLat = -90; double maxLon = -180; double minLat = 90; double minLon = 180; foreach (string coord in coordinates) { string[] line = coord.Split(new string[] { App.DELIMITER }, StringSplitOptions.RemoveEmptyEntries); double lat; double lon; if (double.TryParse(line[1], out lat) && double.TryParse(line[2], out lon)) { maxLat = Math.Max(maxLat, lat); maxLon = Math.Max(maxLon, lon); minLat = Math.Min(minLat, lat); minLon = Math.Min(minLon, lon); polygon.Path.Add(new GeoCoordinate(lat, lon)); } } if (polygon.Path.Count > 0) { // Map1.Center = new GeoCoordinate(minLat + ((maxLat - minLat) / 2), minLon, ((maxLon - minLon) / 2)); Map1.MapElements.Add(polygon); //Map1.SetView(new LocationRectangle(maxLat, minLon, maxLat, maxLon)); Map1.SetView(LocationRectangle.CreateBoundingRectangle(polygon.Path)); } }
public static void SetBound(Map obj, LocationRectangle value) { obj.SetValue(BoundProperty, value); }
public async Task TrySetViewBoundsAsync(LocationRectangle bounds, bool animate) { composedControl.ZoomToBounds(new MapControl.Location(bounds.South, bounds.West), new MapControl.Location(bounds.North, bounds.East)); }
private void statsMap_Loaded(object sender, RoutedEventArgs e) { System.Threading.Thread.Sleep(500); var poiList = ViewModel.PointOfInterestList; if (poiList.Count > 0) { var bounds = new LocationRectangle( poiList.Max((p) => p.Latitude), poiList.Min((p) => p.Longitude), poiList.Min((p) => p.Latitude), poiList.Max((p) => p.Longitude)); statsMap.SetView(bounds); } }
public async Task <List <BingMapPushpin> > GetPushpins(int ammount, LocationRectangle bounds = null, PushpinOptions options = null) { return(await JSRuntime.InvokeAsync <List <BingMapPushpin> >("rpedrettiBlazorComponents.bingMap.devTools.getPushpins", ammount, bounds, options)); }
public MapRenderer2WinPhone() : base() { MessagingCenter.Subscribe <IEnumerable <HeritageProperty> >(this, MapRenderer2.MESSAGE_ADD_AND_ZOOM_ON_PINS, (items) => { Task.Run(async() => { // just wait to give the control time to render and set it's position await Task.Delay(300); // invoke on main thread Dispatcher.BeginInvoke(() => { CustomPushPinWithToolTip prevItem = null; List <GeoCoordinate> coords = new List <GeoCoordinate>(); var layer = new MapLayer(); // loop through all the properties and add them to the list foreach (var item in items) { // create the overlay var overlay = new MapOverlay() { GeoCoordinate = new GeoCoordinate(item.Latitude, item.Longitude), PositionOrigin = new System.Windows.Point(0, 1) }; // create th epin var pin = new CustomPushPinWithToolTip(item, overlay); pin.ToolTipTapped = (i) => { MessagingCenter.Send <Location>(new Location() { Latitude = i.Latitude, Longitude = i.Longitude }, MapRenderer2.MESSAGE_ON_INFO_WINDOW_CLICKED); }; pin.MarkerTapped = (p) => { if (prevItem != null && prevItem != p) { prevItem.HideCallout(); } prevItem = p; var o = p.ParentOverlay; layer.Remove(o); layer.Add(o); this.NativeMap.Center = p.ParentOverlay.GeoCoordinate; }; // set the content for the overlay overlay.Content = pin; // add overlay to layer layer.Add(overlay); // add to the list coords.Add(overlay.GeoCoordinate); } // add to map this.NativeMap.Layers.Add(layer); // zoom in on pins this.NativeMap.SetView(LocationRectangle.CreateBoundingRectangle(coords)); }); }); }); MessagingCenter.Subscribe <IEnumerable <HeritageProperty> >(this, MapRenderer2.MESSAGE_ZOOM_ON_PINS, (items) => { List <GeoCoordinate> coords = new List <GeoCoordinate>(); // loop through all the properties and add them to the list foreach (var item in items) { coords.Add(new GeoCoordinate(item.Latitude, item.Longitude)); } // zoom in on pins this.NativeMap.SetView(LocationRectangle.CreateBoundingRectangle(coords)); }); }
public MapViewRequestedEventArgs(LocationRectangle locRect, MapAnimationKind anim = MapAnimationKind.None) { TargetBounds = locRect; Animation = anim; }
void FitToView() { LocationRectangle setRect = null; if (selected_shape == "Polygon" && (poly != null)) { Debug.WriteLine("Fitting polygon into the view"); setRect = LocationRectangle.CreateBoundingRectangle(poly.Path); } else if (selected_shape == "Polyline" && (polyline != null)) { double north = 0; double west = 0; double south = 0; double east = 0; north = south = polyline.Path[0].Latitude; west = east = polyline.Path[0].Longitude; foreach (var p in polyline.Path.Skip(1)) { if (north < p.Latitude) north = p.Latitude; if (west > p.Longitude) west = p.Longitude; if (south > p.Latitude) south = p.Latitude; if (east < p.Longitude) east = p.Longitude; } setRect = new LocationRectangle(north, west, south, east); } else if (selected_shape == "Markers" && (markerLayer != null)) { Debug.WriteLine("Fitting: " + markerLayer.Count() + " markers into the view"); GeoCoordinate[] geoArr = new GeoCoordinate[markerLayer.Count()]; for (var p = 0; p < markerLayer.Count(); p++) { geoArr[p] = markerLayer[p].GeoCoordinate; } setRect = LocationRectangle.CreateBoundingRectangle(geoArr); } if (setRect != null) { map1.SetView(setRect); } }
public async Task TrySetViewBoundsAsync(LocationRectangle bounds, bool animate) { await composedControl.TrySetViewBoundsAsync(bounds.ToGeoboundingBox(), null, animate?MapAnimationKind.Default : MapAnimationKind.None); }