Exemple #1
0
        public static string GetCategoryName(Android.Content.Res.Resources res, PoiCategory category)
        {
            switch (category)
            {
            case PoiCategory.Historic:
                return(res.GetText(Resource.String.Category_Historic));

            case PoiCategory.Cities:
                return(res.GetText(Resource.String.Category_Cities));

            case PoiCategory.Other:
                return(res.GetText(Resource.String.Category_Other));

            case PoiCategory.Mountains:
                return(res.GetText(Resource.String.Category_Mountains));

            case PoiCategory.Lakes:
                return(res.GetText(Resource.String.Category_Lakes));

            case PoiCategory.ViewTowers:
                return(res.GetText(Resource.String.Category_ViewTowers));

            case PoiCategory.Transmitters:
                return(res.GetText(Resource.String.Category_Transmitters));

            case PoiCategory.Churches:
                return(res.GetText(Resource.String.Category_Churches));

            case PoiCategory.ElevationData:
                return(res.GetText(Resource.String.Category_ElevationData));

            default:
                return("Unknown category");
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns int representing Icon of the category.
        /// </summary>
        /// <param name="category"></param>
        /// <param name="enabled"></param>
        /// <returns></returns>
        public static int GetImage(PoiCategory category, bool enabled = true)
        {
            switch (category)
            {
            case PoiCategory.Historic:
                return(enabled ? Resource.Drawable.c_castle : Resource.Drawable.c_castle_grey);

            case PoiCategory.Cities:
                return(enabled ? Resource.Drawable.c_city : Resource.Drawable.c_city_grey);

            case PoiCategory.Other:
                return(enabled ? Resource.Drawable.c_other : Resource.Drawable.c_other_grey);

            case PoiCategory.Mountains:
                return(enabled ? Resource.Drawable.c_mountain : Resource.Drawable.c_mountain_grey);

            case PoiCategory.Lakes:
                return(enabled ? Resource.Drawable.c_lake : Resource.Drawable.c_lake_grey);

            case PoiCategory.ViewTowers:
                return(enabled ? Resource.Drawable.c_viewtower : Resource.Drawable.c_viewtower_grey);

            case PoiCategory.Transmitters:
                return(enabled ? Resource.Drawable.c_transmitter : Resource.Drawable.c_transmitter_grey);

            case PoiCategory.Churches:
                return(enabled ? Resource.Drawable.c_church : Resource.Drawable.c_church_grey);

            default:
                return(Resource.Drawable.c_basic);
            }
        }
Exemple #3
0
        private static PoiData GetPoiData(string dir, PoiCategory category, PoiCountry country)
        {
            try
            {
                var filename  = $"{dir}\\{GetFileName(category)}";
                var xml       = File.ReadAllText(filename);
                var listOfPoi = GpxFileParser.Parse(xml, category, country, Guid.NewGuid());
                var count     = listOfPoi.Count;
                //DateTime creation = File.GetCreationTime(filename);
                DateTime modificationDate = File.GetLastWriteTime(filename);

                var pd = new PoiData()
                {
                    Category    = category,
                    DateCreated = modificationDate,
                    PointCount  = count,
                    Url         = $"PoiData/{country}/{GetFileName(category)}",
                    Description = "",
                    Id          = GetGuid(country, category)
                };

                return(pd);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
        private Bitmap GetCategoryBitmap(Resources resources, PoiCategory category, Size size)
        {
            var resourceId = Utilities.PoiCategoryHelper.GetImage(category);
            var img        = BitmapFactory.DecodeResource(resources, resourceId);

            return(Bitmap.CreateScaledBitmap(img, size.Width, size.Height, false));
        }
Exemple #5
0
        private static string GetFileName(PoiCategory category)
        {
            switch (category)
            {
            case PoiCategory.Mountains:
                return("peaks.gpx");

            case PoiCategory.Lakes:
                return("lakes.gpx");

            case PoiCategory.ViewTowers:
                return("viewtowers.gpx");

            case PoiCategory.Transmitters:
                return("transmitters.gpx");

            case PoiCategory.Churches:
                return("churches.gpx");

            case PoiCategory.Historic:
                return("historic.gpx");

            case PoiCategory.Cities:
                return("settlements.gpx");

            default:
                throw new ArgumentOutOfRangeException(nameof(category), category, null);
            }
        }
        public Bitmap GetCategoryIcon(PoiCategory category)
        {
            if (!categoryIcon.ContainsKey(category))
            {
                return(defaultIcon);
            }

            return(categoryIcon[category]);
        }
Exemple #7
0
        private static void AddPoiData(CountryData cd, string dir, PoiCategory category, PoiCountry poiCountry)
        {
            var pd = GetPoiData(dir, category, poiCountry);

            if (pd != null && pd.PointCount > 0)
            {
                cd.PoiData.Add(pd);
            }
        }
Exemple #8
0
        public List <WXCategory> GetCategory()
        {
            PoiCategory category = PoiApi.GetCategory(_accessToken, 10000);

            if (category.errcode != ReturnCode.请求成功)
            {
                throw new Exception(category.errmsg);
            }
            List <WXCategory> wXCategories = new List <WXCategory>();

            foreach (string categoryList in category.category_list)
            {
                string[] strArrays = categoryList.Split(new char[] { ',' });
                if (strArrays.Count() == 1)
                {
                    WXCategory wXCategory = new WXCategory()
                    {
                        Id   = Guid.NewGuid().ToString(),
                        Name = strArrays[0]
                    };
                    wXCategories.Add(wXCategory);
                }
                else if (!wXCategories.Exists((WXCategory p) => p.Name == strArrays[0]))
                {
                    WXCategory wXCategory1 = new WXCategory()
                    {
                        Id   = Guid.NewGuid().ToString(),
                        Name = strArrays[0]
                    };
                    WXCategory wXCategory2 = new WXCategory()
                    {
                        Id   = wXCategory1.Id,
                        Name = strArrays[1]
                    };
                    wXCategory1.Child.Add(wXCategory2);
                    wXCategories.Add(wXCategory1);
                }
                else
                {
                    WXCategory wXCategory3 = wXCategories.FirstOrDefault((WXCategory p) => p.Name == strArrays[0]);
                    if (wXCategory3.Child.Exists((WXCategory p) => p.Name == strArrays[1]))
                    {
                        continue;
                    }
                    WXCategory wXCategory4 = new WXCategory()
                    {
                        Id   = wXCategory3.Id,
                        Name = strArrays[1]
                    };
                    wXCategory3.Child.Add(wXCategory4);
                }
            }
            return(wXCategories);
        }
Exemple #9
0
        private static string GetCategoryPart(PoiCategory category)
        {
            switch (category)
            {
            case PoiCategory.Mountains: return("00");

            case PoiCategory.Lakes: return("04");

            case PoiCategory.ViewTowers: return("03");

            case PoiCategory.Transmitters: return("02");

            case PoiCategory.Churches: return("06");

            case PoiCategory.Historic: return("05");

            case PoiCategory.Cities: return("01");

            default:
                throw new ArgumentOutOfRangeException(nameof(category), category, null);
            }
        }
Exemple #10
0
 private void OnCategorySelected(object sender, AdapterView.ItemSelectedEventArgs e)
 {
     _category = (_spinnerCategory.Adapter as CategoryAdapter)[e.Position] ?? PoiCategory.Other;
     _thumbnail.SetImageResource(PoiCategoryHelper.GetImage(_category));
 }
        static public PoiList Parse(string xml, PoiCategory category, PoiCountry country, Guid source, Action <int> OnStart = null, Action <int> OnProgress = null)
        {
            var lastNode = "";

            try
            {
                var listOfPoi = new PoiList();

                XmlDocument gpxDoc = new XmlDocument();
                gpxDoc.LoadXml(xml);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(gpxDoc.NameTable);
                nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/1");
                nsmgr.AddNamespace("ogr", "http://osgeo.org/gdal");
                XmlNodeList nl = gpxDoc.SelectNodes("/x:gpx/x:wpt ", nsmgr);

                OnStart?.Invoke(nl == null ? 0 : nl.Count);

                int i = 0;
                foreach (XmlElement xelement in nl)
                {
                    OnProgress?.Invoke(i++);

                    var lat = xelement.Attributes.GetNamedItem("lat").Value;
                    var lon = xelement.Attributes.GetNamedItem("lon").Value;

                    var nameElement = xelement["name"];
                    var name        = nameElement == null ? "Unnamed" : nameElement.InnerText;

                    var eleElement = xelement["ele"];
                    var ele        = eleElement == null ? "0" : eleElement.InnerText;

                    var    wikidataElement = xelement["wikidata"];
                    string wikidata        = wikidataElement == null ? "" : wikidataElement.InnerText;

                    var    wikipediaElement = xelement["wikipedia"];
                    string wikipedia        = wikipediaElement == null ? "" : wikipediaElement.InnerText;

                    Poi poi = new Poi
                    {
                        Name      = name,
                        Longitude = double.Parse(lon, CultureInfo.InvariantCulture),
                        Latitude  = double.Parse(lat, CultureInfo.InvariantCulture),
                        Altitude  = String.IsNullOrEmpty(ele) ? 0 : double.Parse(ele, CultureInfo.InvariantCulture),
                        Category  = category,
                        Country   = country,
                        Source    = source
                    };
                    if (!String.IsNullOrEmpty(wikipedia))
                    {
                        poi.Wikipedia = wikipedia;
                    }
                    if (!String.IsNullOrEmpty(wikidata))
                    {
                        poi.Wikidata = wikidata;
                    }

                    listOfPoi.Add(poi);

                    lastNode = name;
                }

                return(listOfPoi);
            }
            catch (Exception ex)
            {
                throw new Exception($"Error when parsing GPX file (last node:{lastNode})", ex);
            }
        }
Exemple #12
0
 public int GetPosition(PoiCategory category)
 {
     return(list.IndexOf(category));
 }
Exemple #13
0
 private static Guid GetGuid(PoiCountry country, PoiCategory category)
 {
     return(new Guid(GetCountryPart(country) + GetCategoryPart(category)));
 }