コード例 #1
0
ファイル: Map.xaml.cs プロジェクト: jorik041/diner-wp
        /// <summary>
        /// Constructor
        /// </summary>
        public Map()
        {
            InitializeComponent();

            // Make sure that data context is loaded
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }

            // Set the data context
            DataContext = App.ViewModel;

            // Set up map view & map pushpin
#if WP8
            MapView                  = new Microsoft.Phone.Maps.Controls.Map();
            MapPushpin               = new Microsoft.Phone.Maps.Toolkit.Pushpin();
            MapPushpin.Name          = "MapPushpin";
            MapPushpin.GeoCoordinate = App.ViewModel.Restaurant.Location;

            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(MapView);
            children.Add(MapPushpin);
            MapExtensionsSetup(MapView);
#else
            MapView = new Microsoft.Phone.Controls.Maps.Map();
            MapView.ZoomBarVisibility = Visibility.Visible;
            MapPushpin          = new Microsoft.Phone.Controls.Maps.Pushpin();
            MapPushpin.Location = App.ViewModel.Restaurant.Location;
            MapView.Children.Add(MapPushpin);
#endif
            MapView.ZoomLevel = 12;
            MapView.Center    = App.ViewModel.Restaurant.Location;
            ContentPanel.Children.Add(MapView);
        }
コード例 #2
0
        //Necessary codes to initiate the toolkit map control
        public void MapExtensionsSetup(Map map)
        {
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(map);
            var runtimeFields = this.GetType().GetRuntimeFields();

            foreach (DependencyObject i in children)
            {
                var info = i.GetType().GetProperty("Name");

                if (info != null)
                {
                    string name = (string)info.GetValue(i);

                    if (name != null)
                    {
                        foreach (FieldInfo j in runtimeFields)
                        {
                            if (j.Name == name)
                            {
                                j.SetValue(this, i);
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void ShowNearStops()
        {
            Dispatcher.BeginInvoke(async() =>
            {
                var vm = this.DataContext as NearStopsViewModel;
                var db = new TransportsNantais.Services.SQLiteService();

                ObservableCollection <MapItem> coll = new ObservableCollection <MapItem>();;

                foreach (var ns in vm.NearStops)
                {
                    var s = await db.GetStopByTanIdAsync(ns.CodeLieu);
                    coll.Add(new MapItem()
                    {
                        Name = s.Name, GeoCoordinate = new GeoCoordinate(s.Latitude, s.Longitude)
                    });
                }

                var itemsColl = MapExtensions.GetChildren(MainMap).OfType <MapItemsControl>().First();

                if (itemsColl.Items.Count > 0)
                {
                    itemsColl.Items.Clear();
                }

                foreach (var c in coll)
                {
                    itemsColl.Items.Add(c);
                }
            });
        }
コード例 #4
0
        /// <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;
            }
        }
コード例 #5
0
        private async void mapControl_Hold(object sender, System.Windows.Input.GestureEventArgs e)
        {
            status.Text = "querying for address...";

            var point      = e.GetPosition(mapControl);
            var coordinate = mapControl.ConvertViewportPointToGeoCoordinate(point);

            var pushpin = new Pushpin
            {
                GeoCoordinate = coordinate,
                Content       = ++pinNumber,
            };

            MapExtensions.GetChildren(mapControl).Add(pushpin);

            position.Text = string.Format("Latitude: {0}\nLongitude: {1}\n",
                                          FormatCoordinate(coordinate.Latitude, 'N', 'S'),
                                          FormatCoordinate(coordinate.Longitude, 'E', 'W'));

            ReverseGeocodeQuery query = new ReverseGeocodeQuery {
                GeoCoordinate = coordinate
            };
            IList <MapLocation> results = await query.GetMapLocationsAsync();

            position.Text += string.Format("{0} locations found.\n", results.Count);
            MapLocation location = results.FirstOrDefault();

            if (location != null)
            {
                position.Text += FormatAddress(location.Information.Address);
            }
            status.Text += "complete";
        }
コード例 #6
0
        /// <summary>
        ///  Give item source to map's pushpins.
        /// </summary>
        public void GetPushpins()
        {
            try
            {
                ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(nokiaMap);
                var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

                //current positions
                if (App.ViewModel.CityDetailsViewModel.CurrentLocationCoordinates.Latitude != 0 && App.ViewModel.CityDetailsViewModel.CurrentLocationCoordinates.Longitude != 0)
                {
                    currentLocation = new GeoCoordinate(App.ViewModel.CityDetailsViewModel.CurrentLocationCoordinates.Latitude, App.ViewModel.CityDetailsViewModel.CurrentLocationCoordinates.Longitude);
                    ShowLocation();
                }

                nokiaMap.Center = new GeoCoordinate(App.ViewModel.FullMapViewModel.MapCenterPoint.Latitude, App.ViewModel.FullMapViewModel.MapCenterPoint.Longitude);
                if (obj.ItemsSource == null)
                {
                    obj.ItemsSource = this.lstCityPushpin;// App.ViewModel.FullMapViewModel.CityCategoryPushpinsList;
                }
                else
                {
                    obj.ItemsSource = this.lstCityPushpin;// App.ViewModel.FullMapViewModel.CityCategoryPushpinsList;
                }
                AddPushpins();
            }
            catch (Exception)
            {
                MessageBox.Show(App.ViewModel.FullMapViewModel.MessageDialog);
            }
        }
コード例 #7
0
        private MapItemsControl GetMPC()
        {
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(theMap);
            var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

            return(obj);
        }
コード例 #8
0
        private void start_Click(object sender, EventArgs e)
        {
            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false;
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = true;

            service = new Geolocator();
            service.DesiredAccuracy   = PositionAccuracy.High;
            service.MovementThreshold = 1.0;
            service.PositionChanged  += service_PositionChanged;
            service.StatusChanged    += service_StatusChanged;

            position.Text    = string.Empty;
            status.Text      = service.LocationStatus.ToString();
            mapControl.Pitch = 45.0;

            var startPin = new Pushpin
            {
                GeoCoordinate = marker.GeoCoordinate,
                Content       = "Start"
            };

            MapExtensions.GetChildren(mapControl).Add(startPin);

            routeLine = new MapPolyline
            {
                StrokeColor     = (Color)Resources["PhoneAccentColor"],
                StrokeThickness = (double)Resources["PhoneStrokeThickness"]
            };
            routeLine.Path.Add(marker.GeoCoordinate);
            mapControl.MapElements.Add(routeLine);
        }
コード例 #9
0
        private void PopulateMap(List <Place> placeList)
        {
            //var pushpinTemplate = Resources["PushpinTemplate"] as DataTemplate;
            //var pushpins = new List<Pushpin>();

            foreach (var place in placeList)
            {
                place.LastUpdate = "Updated: " + place.UpdatedAt.ToString("f");
                place.Icon       = GetSource(place);
                place.Coordinate = new GeoCoordinate(place.Latitude, place.Longitude);
                //Pushpin pp = new Pushpin
                //             {
                //                 GeoCoordinate = new GeoCoordinate(place.Latitude, place.Longitude),
                //                 ContentTemplate = pushpinTemplate,
                //                 Content = place.Icon
                //             };
                //pushpins.Add(pp);
            }

            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(myMap);
            var obj = children.FirstOrDefault(x => x is MapItemsControl) as MapItemsControl;

            if (obj != null)
            {
                obj.ItemsSource = App.ViewModel.Items;
            }
            //var clusterer = new ClustersGenerator(myMap, pushpins, Resources["ClusterTemplate"] as DataTemplate);
            myMap.SetView(new GeoCoordinate(53.510138, -7.865643), 7.0);
        }
コード例 #10
0
        private static void OnPushPinPropertyChanged(DependencyObject d,
                                                     DependencyPropertyChangedEventArgs e)
        {
            UIElement uie     = (UIElement)d;
            var       pushpin = MapExtensions.GetChildren((Map)uie).OfType <MapItemsControl>().FirstOrDefault();

            pushpin.ItemsSource = (IEnumerable)e.NewValue;
        }
コード例 #11
0
        private void BindMapItemsControlItemsSource(string name, System.Collections.IEnumerable source)
        {
            // Finds the right control.
            MapItemsControl mapItemsControl = MapExtensions.GetChildren(MapControl)
                                              .OfType <MapItemsControl>()
                                              .First(mic => mic.Name == name);

            // Binds the property.
            mapItemsControl.ItemsSource = source;
        }
コード例 #12
0
ファイル: MainPage.xaml.cs プロジェクト: tOmoness/.net-sdk
        // These helpers enable the Pushpin control from Windows Phone Toolkit
        // to be used in representing the artists and bands on the Map control.
        private void InitializeMap(Map map)
        {
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(map);
            IEnumerable <FieldInfo> runtimeFields            = this.GetType().GetRuntimeFields();

            foreach (DependencyObject i in children)
            {
                SetChildItemField(i, runtimeFields);
            }
        }
コード例 #13
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(MyMap);
            var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

            if (obj.ItemsSource == null)
            {
                obj.ItemsSource = ViewModel.TripPoints;
            }
        }
コード例 #14
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            Trip currentTrip = ViewModel.Trip;

            if (currentTrip.IsActif)
            {
                EndStack.Visibility = Visibility.Collapsed;
            }
            else
            {
                EndStack.Visibility = Visibility.Visible;
            }
            //Bind les POI a la map
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(statsMap);
            var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

            if (obj.ItemsSource != null)
            {
                (obj.ItemsSource as IList).Clear();
                obj.ItemsSource = null;
            }
            obj.ItemsSource = (ViewModel.PointOfInterestList);

            //Ajout du départ
            MapLayer layer1   = new MapLayer();
            Pushpin  pushpin1 = new Pushpin();

            pushpin1.GeoCoordinate = currentTrip.CoordinateDeparture;
            pushpin1.Background    = new SolidColorBrush(Color.FromArgb(255, 105, 105, 105));
            pushpin1.Content       = AppResources.AddTripDeparture;
            MapOverlay overlay1 = new MapOverlay();

            overlay1.Content        = pushpin1;
            overlay1.GeoCoordinate  = currentTrip.CoordinateDeparture;
            overlay1.PositionOrigin = new Point(0, 1);
            layer1.Add(overlay1);
            statsMap.Layers.Add(layer1);

            //Ajout de la destination
            MapLayer layer2   = new MapLayer();
            Pushpin  pushpin2 = new Pushpin();

            pushpin2.GeoCoordinate = currentTrip.CoordinateDestination;
            pushpin2.Content       = AppResources.AddTripArrival;
            pushpin2.Background    = new SolidColorBrush(Color.FromArgb(255, 105, 105, 105));
            MapOverlay overlay2 = new MapOverlay();

            overlay2.Content        = pushpin2;
            overlay2.GeoCoordinate  = currentTrip.CoordinateDestination;
            overlay2.PositionOrigin = new Point(0, 1);
            layer2.Add(overlay2);
            statsMap.Layers.Add(layer2);
        }
コード例 #15
0
ファイル: MainPage.xaml.cs プロジェクト: mulflar/SocialApp
        //crea una capa en mapa y bindea la lista a pushpins
        private void pinchosmapa()
        {
            SystemTray.ProgressIndicator.Text = "Obteniendo locales y eventos cercanos";
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(mapacentral);
            var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

            localespincho(mapacentral.Center.Latitude, mapacentral.Center.Longitude);
            obj.ItemsSource           = listapinchos;
            listacercanos.DataContext = listapinchos;
            SetProgressindicator(false);
        }
コード例 #16
0
        public MainPage()
        {
            InitializeComponent();
            DataContext = _mainViewModel;

            var control = MapExtensions.GetChildren(MyMap).OfType <MapItemsControl>().FirstOrDefault();

            if (control != null)
            {
                control.ItemsSource = _mainViewModel.Planes;
            }
        }
コード例 #17
0
        private static void OnLayersChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var map            = (EpflMap)obj;
            var itemsContainer = MapExtensions.GetChildren(map.LayoutRoot).OfType <MapItemsControl>().ElementAt(1);

            itemsContainer.Items.Clear();
            foreach (var layer in (PocketCampus.Map.Models.MapLayer[])args.NewValue)
            {
                foreach (var item in layer.Items)
                {
                    itemsContainer.Items.Add(item);
                }
            }
        }
コード例 #18
0
        private void loadData()
        {
            ////Bind les POI a la map
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(MyMap);
            var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

            if (obj.ItemsSource != null)
            {
                removeTempMapLayer();
                (obj.ItemsSource as IList).Clear();
                obj.ItemsSource = null;
            }
            obj.ItemsSource = ViewModel.PointOfInterestList;
        }
コード例 #19
0
        protected override void OnApplyTemplate()
        #endif
        {
            base.OnApplyTemplate();

            map = GetTemplateChild(PartNames.Map) as Map;

            // Validate the template
            if (map == null)
            {
                throw new InvalidOperationException(string.Format("{0} template is invalid. A {1} named {2} must be supplied.", GetType().Name, typeof(Map).Name, PartNames.Map));
            }

            // Connect credentials
            #if WP7
            map.CredentialsProvider = credentials;
            #endif

            #if WP8
            if (credentials != null)
            {
                MapsSettings.ApplicationContext.ApplicationId       = credentials.ApplicationId;
                MapsSettings.ApplicationContext.AuthenticationToken = credentials.AuthenticationToken;
            }
            #endif

            #if WIN_RT
            map.Credentials = credentials;
            #endif

            // Update the margin
            UpdateMargin();

            // Connect data
            map.DataContext = arItems;
            #if WP8
            // We must use the toolkit to get the child map items controls and set their items source properly
            foreach (var itemsControl in MapExtensions.GetChildren(map).OfType <MapItemsControl>())
            {
                itemsControl.ItemsSource = arItems;
            }
            #endif

            #if WIN_RT
            // Set initial values for properties that can't be data bound in Windows 8
            map.Center    = Location;
            map.ZoomLevel = PercentBingZoomConverter.PercentToMapLevel(ZoomLevel);
            #endif
        }
コード例 #20
0
        private void refreshLocationsOnMap()
        {
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(FrequentLocationsMap);
            var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

            if (obj.Items == null || obj.Items.Count == 0)
            {
                obj.ItemsSource = frequentLMLocations;
                //obj.Items.Clear();
            }

            if (MyCoordinates != null && MyCoordinates.Count != 0)
            {
                FrequentLocationsMap.Center = MyCoordinates[MyCoordinates.Count - 1];
                FrequentLocationsMap.SetView(MyCoordinates[MyCoordinates.Count - 1], 10, MapAnimationKind.Linear);
            }
        }
コード例 #21
0
        private void ToForgeChildren()
        {
            if (children == null)
            {
                children = MapExtensions.GetChildren(myMap);

                marker          = children.FirstOrDefault(x => x.GetType() == typeof(UserLocationMarker)) as UserLocationMarker;
                mapItemsControl = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;
            }

            marker.GeoCoordinate = position.Coordinate.ToGeoCoordinate();

            if (pushpins.Count != 0)
            {
                mapItemsControl.ItemsSource = pushpins;
            }
        }
コード例 #22
0
        public HomePage()
        {
            InitializeComponent();

            if ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible)
            {
                LogoLightTheme.Visibility = Visibility.Collapsed;
                LogoDarkTheme.Visibility  = Visibility.Visible;
            }
            else
            {
                LogoLightTheme.Visibility = Visibility.Visible;
                LogoDarkTheme.Visibility  = Visibility.Collapsed;
            }

            // for some reason InitializeComponent doesn't initialize PushPin
            AddressPushPin = MapExtensions.GetChildren(map).FirstOrDefault() as Pushpin;
        }
コード例 #23
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            // myMap.DataContext = App.ViewModel;
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(myMap);
            var obj = children.FirstOrDefault(x => x is MapItemsControl) as MapItemsControl;

            if (obj != null)
            {
                obj.ItemsSource = App.ViewModel.Items;
            }
            //myMap.SetView(new GeoCoordinate(53.510138, -7.865643), 7.2);

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
コード例 #24
0
 /// <summary>
 /// load city category details.
 /// </summary>
 public void LoadCategoriesData()
 {
     try
     {
         this.Dispatcher.BeginInvoke(() =>
         {
             ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(nokiaMap);
             var obj         = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;
             nokiaMap.Center = new GeoCoordinate(App.ViewModel.CityCategoryDetailViewModel.MapCenterPoint.Latitude, App.ViewModel.CityCategoryDetailViewModel.MapCenterPoint.Longitude);
             if (obj.ItemsSource == null)
             {
                 obj.ItemsSource = App.ViewModel.CityCategoryDetailViewModel.CityCategoryPushpinsList;
             }
         });
     }
     catch (Exception)
     {
     }
 }
コード例 #25
0
        private async void ToggleLocation(object sender, EventArgs e)
        {
            Geolocator geo = new Geolocator();

            geo.DesiredAccuracy = PositionAccuracy.High;
            Geoposition position = null;

            // Se intenta ubicar la posición de nuestro teléfono
            try
            {
                position = await geo.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("Ubicación está desactivada en tu dispositivo");
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                try
                {
                    MyCoordinate = new GeoCoordinate(position.Coordinate.Latitude, position.Coordinate.Longitude);
                    myMap.SetView(MyCoordinate, 15);
                    var children = MapExtensions.GetChildren(map);
                    var ob       = children.Where(x => x.GetType() == typeof(UserLocationMarker)).FirstOrDefault();
                    UserLocationMarker marker = (UserLocationMarker)ob;

                    marker.GeoCoordinate = coordinate;
                    marker.Visibility    = System.Windows.Visibility.Visible;
                }
                catch (Exception)
                {
                    //      MessageBox.Show("No podemos obtener lugares cercanos a tu locacíon ,verifica tu conexión a datos");
                }
            });

            // Se mueve el centro del mapa hacia nuestra ubicación
            this.map.Center.Latitude  = position.Coordinate.Latitude;
            this.map.Center.Longitude = position.Coordinate.Longitude;
            this.map.ZoomLevel        = 15;
        }
コード例 #26
0
        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}

        private async void mapControl_Loaded(object sender, RoutedEventArgs e)
        {
            status.Text = "querying for current location...";

            Geolocator  locator     = new Geolocator();
            Geoposition geoPosition = await locator.GetGeopositionAsync();

            GeoCoordinate coordinate = geoPosition.Coordinate.ToGeoCoordinate();

            mapControl.Center    = coordinate;
            mapControl.ZoomLevel = 10;

            position.Text = string.Format("Latitude: {0}\nLongitude: {1}\n",
                                          FormatCoordinate(coordinate.Latitude, 'N', 'S'),
                                          FormatCoordinate(coordinate.Longitude, 'E', 'W'));

            marker = new UserLocationMarker();
            marker.GeoCoordinate = coordinate;
            MapExtensions.GetChildren(mapControl).Add(marker);

            status.Text += "complete";
        }
コード例 #27
0
        public StopDetailsView()
        {
            InitializeComponent();
            pushPinLayer = new MapLayer();
            this.MainMap.Layers.Add(pushPinLayer);

            Messenger.Default.Register <GenericMessage <GeoCoordinate> >(this, (msg) =>
            {
                if (msg.Sender == this.DataContext)
                {
                    pushPinLayer.Clear();

                    this.MainMap.Center    = msg.Content;
                    this.MainMap.ZoomLevel = 15;

                    Pushpin stop       = new Pushpin();
                    stop.GeoCoordinate = msg.Content;

                    var itemsColl = MapExtensions.GetChildren(MainMap).OfType <MapItemsControl>().First();
                    itemsColl.Items.Clear();
                    itemsColl.Items.Add(stop);
                }
            });
        }
コード例 #28
0
        private void PopulateMap(ItemViewModel pl)
        {
            pl.LastUpdate = "Updated: " + pl.UpdatedAt.ToString("f");
            pl.Icon       = GetSource(pl);
            pl.Coordinate = new GeoCoordinate(pl.Latitude, pl.Longitude);

            List <ItemViewModel> places = new List <ItemViewModel>();

            places.Add(pl);
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(myMap);
            MapItemsControl obj = new MapItemsControl();

            obj.Items.Clear();
            obj.ItemsSource = null;
            obj             = children.FirstOrDefault(x => x is MapItemsControl) as MapItemsControl;

            if (obj != null && obj.Items.Count == 0)
            {
                obj.ItemsSource = places;
                TbkTitle.Text   = pl.Title;
                TbkReport.Text  = pl.Report;
                TbkUpdated.Text = "Updated: " + pl.UpdatedAt.ToString("f");
            }
        }
コード例 #29
0
        //crea una capa en mapa y bindea la lista a pushpins.
        //Pide localizaciones de pinchos, las adapta al objeto pincho y las almacena en una lista ordenados por distancia
        //tambien crea una lista mas reducida para mostrar sobre el mapa
        public async void localespincho(double latitude, double longitude)
        {
            ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(mapacentral);
            var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

            listado = await vm.GetPinchos(latitude, longitude);

            prog.IsVisible = true;
            prog.Text      = "Pintando el mundo";
            if (listado != null)
            {
                listapinchos.Clear();
                foreach (VModel.Pincho item in listado)
                {
                    listapinchos.Add(item);
                }
            }
            placereduced    = vm.PlaceReduced;
            obj.ItemsSource = listapinchos;
            GeoCoordinate centro = new GeoCoordinate(mapacentral.Center.Latitude, mapacentral.Center.Longitude);

            mapacentral.SetView(centro, mapacentral.ZoomLevel);
            prog.IsVisible = false;
        }
コード例 #30
0
        /// <summary>
        /// Loads all data of a dataset
        /// </summary>
        /// <returns></returns>
        public async Task LoadCategoriesData()
        {
            try
            {
                ObservableCollection <DependencyObject> children = MapExtensions.GetChildren(nokiaMap);
                var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;
                nokiaMap.Center = new GeoCoordinate(App.ViewModel.CityDetailsViewModel.MapCenterPoint.Latitude, App.ViewModel.CityDetailsViewModel.MapCenterPoint.Longitude);

                var data = (this.DataContext as GovFinderData);
                App.ViewModel.CityDetailsViewModel.CurrentCategoryName = data.DataSetName;
                //check if ApiUrl not null
                if (!string.IsNullOrEmpty(data.ApiUrl))
                {
                    this.Dispatcher.BeginInvoke(() =>
                    {
                        App.ViewModel.CityDetailsViewModel.CityCategoryItemsList.Clear();
                        App.ViewModel.CityDetailsViewModel.CityCategoryPushpinsList.Clear();
                    });
                    //Check if AllCityCategoryItems contains key for this category
                    //if (App.ViewModel.CityDetailsViewModel.AllCityCategoryItems.ContainsKey(data.DataSetName))
                    //{
                    //    this.Dispatcher.BeginInvoke(() =>
                    //             {
                    //                 this.pbProgressBar.IsIndeterminate = true;
                    //                 App.ViewModel.CityDetailsViewModel.CityCategoryItemsList = App.ViewModel.CityDetailsViewModel.AllCityCategoryItems[data.DataSetName].ToObservableCollection();
                    //                 this.pbProgressBar.IsIndeterminate = false;
                    //                 var firstData = App.ViewModel.CityDetailsViewModel.CityCategoryItemsList.FirstOrDefault();
                    //                 if (firstData != null)
                    //                 {
                    //                     App.ViewModel.CityDetailsViewModel.MapCenterPoint = firstData.Coordinate;
                    //                     nokiaMap.Center = new GeoCoordinate(App.ViewModel.CityDetailsViewModel.MapCenterPoint.Latitude, App.ViewModel.CityDetailsViewModel.MapCenterPoint.Longitude);
                    //                     if (App.ViewModel.CityDetailsViewModel.MapCenterPoint.Latitude == 0 && App.ViewModel.CityDetailsViewModel.MapCenterPoint.Longitude == 0)
                    //                     {
                    //                         nokiaMap.Center = new GeoCoordinate(App.ViewModel.CityDetailsViewModel.CurrentLocationCoordinates.Latitude, App.ViewModel.CityDetailsViewModel.CurrentLocationCoordinates.Longitude);
                    //                     }

                    //                 }
                    //                 foreach (var pushpin in App.ViewModel.CityDetailsViewModel.CityCategoryItemsList.Take(40).ToObservableCollection())
                    //                 {
                    //                     if (pushpin.Coordinate.Latitude != 0 && pushpin.Coordinate.Longitude != 0)
                    //                     {
                    //                         App.ViewModel.CityDetailsViewModel.CityCategoryPushpinsList.Add(pushpin);
                    //                     }
                    //                 }

                    //                 this.cityItemsList.ItemsSource = App.ViewModel.CityDetailsViewModel.CityCategoryItemsList;
                    //                 if (obj.ItemsSource == null)
                    //                 {
                    //                     obj.ItemsSource = App.ViewModel.CityDetailsViewModel.CityCategoryPushpinsList;
                    //                 }
                    //                 this.pbProgressBar.IsIndeterminate = false;
                    //             });
                    //}
                    //else
                    //{
                    cts = new CancellationTokenSource();
                    Task <string> taskGetCityItemDetails = Task <string> .Run <string>(() =>
                    {
                        App.ViewModel.CityDetailsViewModel.GetCityItemDetails(data.ApiUrl, data);
                        return("");
                    }, cts.Token);

                    taskGetCityItemDetails.ContinueWith((Task <string> Value) =>
                    {
                        this.Dispatcher.BeginInvoke(() =>
                        {
                            //this.cityItemsList.DataContext = App.ViewModel;
                            this.cityItemsList.ItemsSource = App.ViewModel.CityDetailsViewModel.CityCategoryItemsList;
                            if (obj.ItemsSource == null)
                            {
                                obj.ItemsSource = App.ViewModel.CityDetailsViewModel.CityCategoryPushpinsList;
                            }
                            nokiaMap.Center = new GeoCoordinate(App.ViewModel.CityDetailsViewModel.MapCenterPoint.Latitude, App.ViewModel.CityDetailsViewModel.MapCenterPoint.Longitude);
                            this.pbProgressBar.IsIndeterminate = App.ViewModel.CityDetailsViewModel.IsDataLoading;
                        });
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
                //}
            }
            catch (Exception)
            {
                MessageBox.Show(App.ViewModel.CityDetailsViewModel.MessageDialog);
            }
        }