Пример #1
0
 /// <summary>
 /// Load reads map information from a xml file
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 public bool Load(string filename)
 {
     Xdoc = XDocument.Load(filename);
     if (!Xdoc.Equals(null))
     {
         double left   = Convert.ToDouble(Xdoc.Root.Element("bounds").Attribute("minlon").Value);
         double top    = Convert.ToDouble(Xdoc.Root.Element("bounds").Attribute("maxlat").Value);
         double right  = Convert.ToDouble(Xdoc.Root.Element("bounds").Attribute("maxlon").Value);
         double bottom = Convert.ToDouble(Xdoc.Root.Element("bounds").Attribute("minlat").Value);
         Tile = new TileBound(MercatorHelper.ToMeters(top, left), MercatorHelper.ToMeters(bottom, right));
         return(true);
     }
     return(false);
 }
Пример #2
0
        /// <summary>
        /// BBox gets map information for the geo location
        /// </summary>
        /// <param name="left"></param>
        /// <param name="bottom"></param>
        /// <param name="right"></param>
        /// <param name="top"></param>
        /// <param name="err"></param>
        /// <returns></returns>
        public bool BBox(double left, double bottom, double right, double top, out string err)
        {
            var mapRequest = OsmMapUrl + "bbox=" + left.ToString() + "," + bottom.ToString() + "," + right.ToString() + "," + top.ToString();

            Xdoc = Request(mapRequest, out err);
            if (Xdoc != null)
            {
                if (absoluteAnchor)
                {
                    Tile           = new TileBound(MercatorHelper.ToMeters(top, left), MercatorHelper.ToMeters(bottom, right));
                    absoluteAnchor = false;
                }
                return(true);
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// NATURAL
        /// Support for Natural like map elements
        /// TODO:
        /// - Trees: rows, woods.
        /// - other naturals
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Natural> Natural()
        {
            var nodes = (from e in Xdoc.Descendants("node")
                         where e.Attribute("visible").Value == "true"
                         from t in e.Descendants("tag")
                         where t.Attribute("k").Value == "natural" && t.Attribute("v").Value == "tree"
                         select new
            {
                Id = e.Attribute("id").Value,
                Name = t.Attribute("v").Value,
                Lat = Convert.ToDouble(e.Attribute("lat").Value),
                Long = Convert.ToDouble(e.Attribute("lon").Value),
                Element = e
            });

            foreach (var node in nodes)
            {
                NaturalData data = default(NaturalData);
                data.circumference = DefaultTreeCircumference;
                data.height        = DefaultTreeHeight;
                foreach (var tag in node.Element.Descendants("tag"))
                {
                    switch (tag.Attribute("k").Value.ToLower())
                    {
                    case "genus":
                        data.genus = tag.Attribute("v").Value;
                        break;

                    case "leaf_type":
                        data.leaf_type = tag.Attribute("v").Value;
                        break;

                    case "circumference":
                        MatchFloat(tag.Attribute("v").Value, out data.circumference);
                        break;

                    case "height":
                        MatchFloat(tag.Attribute("v").Value, out data.height);
                        break;
                    }
                }
                var pos = MercatorHelper.ToMeters(node.Lat, node.Long);
                yield return(new Natural(node.Id, new Vector2(pos.X - Tile.Center.X, pos.Y - Tile.Center.Y), data));
            }
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="way"></param>
        /// <returns></returns>
        private Polygon CreateFootprint(XElement way)
        {
            var footprint = new Polygon();

            foreach (var elt in way.Descendants("nd"))
            {
                // find node that matches this ways' nodes ref
                var node = FindNodeById(elt.Attribute("ref").Value);
                if (node != null)
                {
                    var pos = MercatorHelper.ToMeters(
                        Convert.ToDouble(node.Attribute("lat").Value),
                        Convert.ToDouble(node.Attribute("lon").Value));
                    footprint.Points.Add(new Vector2(pos.X - Tile.Center.X, pos.Y - Tile.Center.Y));
                }
            }
            return(footprint);
        }