コード例 #1
0
ファイル: AutoComplete.cs プロジェクト: netast/taxi
 void onDoneButtonClicked(object sender, EventArgs e)
 {
     if (DoneCommand != null && DoneCommand.CanExecute(null))
     {
         DoneCommand.Execute(null);
     }
 }
コード例 #2
0
        private async void RefreshSites()
        {
            if (IsBusy || !IsActive)
            {
                return;
            }

            IsBusy = true;

            if (firstLocation == null)
            {
                firstLocation = await _siteService.GetLocation();

                if (firstLocation != null)
                {
                    VisibleRegion = MapSpan.FromCenterAndRadius(new Position(firstLocation.Latitude, firstLocation.Longitude), VisibleRegion.Radius);
                    IsBusy        = false;
                    return;
                }
            }

            try
            {
                var distanceRadians =
                    DegreesToRadians(Math.Max(VisibleRegion.LatitudeDegrees, VisibleRegion.LongitudeDegrees) / 2);

                var sites = await _siteService.GetNearBySites(MapCenter.Latitude, MapCenter.Longitude, distanceRadians);

                Sites = new ObservableCollection <Site>(sites);

                var pins = new List <ILocationViewModel>();
                foreach (var site in sites)
                {
                    var localSite = site;
                    pins.Add(new LocationViewModel
                    {
                        Key         = site.SiteId.ToString(),
                        Title       = site.SiteName,
                        Latitude    = site.Latitude,
                        Longitude   = site.Longitude,
                        Description = string.Format("{0}", site.IsPublic.HasValue ? site.IsPublic.Value ? "Allmän" : "Privat" : string.Empty),
                        Command     = new Command(() => DoneCommand.Execute(localSite))
                    });
                }

                //UpdatePins(pins);
                Pins = new ObservableCollection <ILocationViewModel>(pins);
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #3
0
        //(CDLTLL) RefreshMap() with real data loading from services/mock is called only if VisibleRegion or Map-Zoom has changed
        private async void ReloadMapInfo()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            if (_firstLocation == null)
            {
                _firstLocation = await GetLocation();

                if (_firstLocation != null)
                {
                    VisibleRegion = MapSpan.FromCenterAndRadius(new Position(_firstLocation.Latitude, _firstLocation.Longitude), VisibleRegion.Radius);
                    IsBusy        = false;
                    return;
                }
            }

            try
            {
                var distanceRadians =
                    DegreesToRadians(Math.Max(VisibleRegion.LatitudeDegrees, VisibleRegion.LongitudeDegrees) / 2);

                var center            = VisibleRegion.Center;
                var halfheightDegrees = VisibleRegion.LatitudeDegrees / 2;
                var halfwidthDegrees  = VisibleRegion.LongitudeDegrees / 2;

                var topLatitude    = center.Latitude + halfheightDegrees;
                var leftLongitude  = center.Longitude - halfwidthDegrees;
                var bottomLatitude = center.Latitude - halfheightDegrees;
                var rightLongitude = center.Longitude + halfwidthDegrees;

                // Adjust for Internation Date Line (+/- 180 degrees longitude)
                if (leftLongitude < -180)
                {
                    leftLongitude = 180 + (180 + leftLongitude);
                }

                if (rightLongitude > 180)
                {
                    rightLongitude = (rightLongitude - 180) - 180;
                }

                // (CDLTLL) Query and obtain data from a real service or from the mock service depending on the injected implementation
                var vehiclesInCurrentMapArea = await _vehiclesService.GetVehiclesInArea(this.UrlPrefix,
                                                                                        CurrentTenantId,
                                                                                        topLatitude,
                                                                                        leftLongitude,
                                                                                        bottomLatitude,
                                                                                        rightLongitude);

                //(CDLTLL - Check this, not being used)
                Vehicles = new ObservableCollection <Vehicle>(vehiclesInCurrentMapArea);

                var pinsList = new List <ILocationViewModel>();
                foreach (Vehicle vehicle in vehiclesInCurrentMapArea)
                {
                    Vehicle localVehicle = vehicle;
                    pinsList.Add(new LocationViewModel
                    {
                        Key         = vehicle.Id.ToString(),
                        Title       = vehicle.Make + " " + vehicle.Model,
                        Latitude    = vehicle.Latitude,
                        Longitude   = vehicle.Longitude,
                        Description = "LicensePlate: " + vehicle.LicensePlate,
                        Command     = new Command(() => DoneCommand.Execute(localVehicle))
                    });
                }

                //UpdatePins(pins);
                if (Pins != null)
                {
                    Pins.Clear();
                }
                Pins = new ObservableCollection <ILocationViewModel>(pinsList);
            }
            finally
            {
                IsBusy = false;
            }
        }