Пример #1
0
        private async Task UpdateMetarInfo(MetarResult response)
        {
            IsBusy      = false;
            AirportCode = string.Empty;
            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                DisplayError(Localization.Error_Occured, response.StatusCode.ToString());
                return;
            }

            var airport       = Airport.MapFromResponse(response.AirportIdentifier, response.MetarResponse);
            var alreadyExists = Airports.FirstOrDefault(x => x.Name == airport.Name);

            if (alreadyExists == null)
            {
                Airports.Add(airport);
            }
            else
            {
                alreadyExists.Copy(airport);
                OnPropertyChanged(nameof(Airports));
            }
            HasSavedItems = Airports != null && Airports.Any();
            await AirportService.SaveAirport(airport, new System.Threading.CancellationToken()).ConfigureAwait(false);
        }
Пример #2
0
        private async Task DeleteAirport(Airport airport)
        {
            if (Airports.Any() && Airports.Contains(airport))
            {
                await AirportService.DeleteAirport(airport.Id, new System.Threading.CancellationToken()).ConfigureAwait(false);

                Airports.Remove(airport);
            }
            HasSavedItems = Airports != null && Airports.Any();
        }
Пример #3
0
        private void LoadSavedAirports()
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                var airports = await AirportService.GetAllAirports(new System.Threading.CancellationToken()).ConfigureAwait(false);
                foreach (var airport in airports)
                {
                    var item = Airports.FirstOrDefault(x => x.Name == airport.Name);
                    if (item != null)
                    {
                        continue;
                    }

                    Airports.Add(airport);
                }
                HasSavedItems = Airports != null && Airports.Any();
            });
        }
Пример #4
0
        /// <summary>
        /// Returns the HREF string suitable for use in an IMG tag (i.e., for a static map vs. a dynamic map)
        /// <param name="szMapKey">The key for using the google maps API</param>
        /// <param name="width">The width for the static map</param>
        /// <param name="height">The height for the static map</param>
        /// </summary>
        public string StaticMapHRef(string szMapKey, int height, int width)
        {
            StringBuilder sb = new StringBuilder(String.Format(CultureInfo.InvariantCulture, "https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid&key={0}&size={1}x{2}", HttpUtility.UrlEncode(szMapKey), width, height));

            bool fHasRoute = Airports != null && Airports.Any();
            bool fHasPath  = Path != null && Path.Any() && ShowRoute;

            if (!String.IsNullOrEmpty(StaticMapAdditionalParams))
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "&{0}", StaticMapAdditionalParams);
            }

            if (fHasPath || fHasRoute)
            {
                List <List <string> > lstSegments = new List <List <string> >();
                if (fHasRoute)
                {
                    List <string> lstMarkers = new List <string>();
                    foreach (AirportList al in Airports)
                    {
                        List <string> lstSegment = new List <string>();
                        lstSegments.Add(lstSegment);
                        foreach (airport ap in al.GetAirportList())
                        {
                            string szSegment = String.Format(CultureInfo.InvariantCulture, "{0:F6},{1:F6}", ap.LatLong.Latitude, ap.LatLong.Longitude);
                            lstMarkers.Add(szSegment);
                            lstSegment.Add(szSegment);
                        }
                    }

                    if (ShowMarkers)
                    {
                        sb.Append("&markers=color:red|" + String.Join("|", lstMarkers));
                    }
                }
                if (ShowRoute)
                {
                    string szPath = string.Empty;
                    if (fHasPath)
                    {
                        List <string> lstPath = new List <string>();
                        foreach (LatLong ll in Path)
                        {
                            lstPath.Add(String.Format(CultureInfo.InvariantCulture, "{0:F6},{1:F6}", ll.Latitude, ll.Longitude));
                        }
                        szPath = String.Join("|", lstPath);
                    }

                    // always connect the segments...
                    foreach (List <string> segment in lstSegments)
                    {
                        sb.Append("&path=color:0x0000FF88|weight:5|geodesic:true|" + String.Join("|", segment));
                    }

                    // and add the path, if possible
                    if (sb.Length + szPath.Length < 8100)
                    {
                        sb.Append("&path=color:0xFF000088|weight:5|" + szPath);
                    }
                }
            }
            else
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "&center={0:F8},{1:F8}&zoom={2}", MapCenter.Latitude, MapCenter.Longitude, (int)ZoomFactor);
            }

            return(sb.ToString());
        }