Example #1
0
 public Node(XmlNode node)
 {
     ID        = XmlGetter.GetAttribute <ulong>("id", node.Attributes);
     Latitude  = XmlGetter.GetAttribute <float>("lat", node.Attributes);
     Longitude = XmlGetter.GetAttribute <float>("lon", node.Attributes);
     X         = (float)MercatorProjection.lonToX(Longitude);
     Y         = (float)MercatorProjection.latToY(Latitude);
 }
Example #2
0
        public Bounds(XmlNode node)
        {
            MinLat = XmlGetter.GetAttribute <float>("minlat", node.Attributes);
            MaxLat = XmlGetter.GetAttribute <float>("maxlat", node.Attributes);
            MinLon = XmlGetter.GetAttribute <float>("minlon", node.Attributes);
            MaxLon = XmlGetter.GetAttribute <float>("maxlon", node.Attributes);

            float x = (float)((MercatorProjection.lonToX(MaxLon) + MercatorProjection.lonToX(MinLon)) / 2);
            float y = (float)((MercatorProjection.latToY(MaxLat) + MercatorProjection.latToY(MinLat)) / 2);

            Center = new Vector3(x, 0, y);
        }
Example #3
0
        static List <Node> GetWayNodes(XmlNode node, Dictionary <ulong, Node> nodesDictionary)
        {
            List <Node> nodes = new List <Node>();

            XmlNodeList nds = node.SelectNodes("nd");

            foreach (XmlNode n in nds)
            {
                nodes.Add(nodesDictionary[XmlGetter.GetAttribute <ulong>("ref", n.Attributes)]);
            }

            return(nodes);
        }
Example #4
0
 void GenerateLines(List <Way> ways, List <Way> lines)
 {
     foreach (Way line in ways)
     {
         XmlNodeList tags = line.Node.SelectNodes("tag");
         if (tags.Count == 0)
         {
             continue;
         }
         bool  road  = false;
         bool  water = false;
         float width = 2;
         foreach (XmlNode tag in tags)
         {
             string key = XmlGetter.GetAttribute <string>("k", tag.Attributes);
             string val = XmlGetter.GetAttribute <string>("v", tag.Attributes);
             foreach (string lineKey in roadlineKeys)
             {
                 if (lineKey == key)
                 {
                     road = true;
                     break;
                 }
             }
             foreach (string lineKey in waterlineKeys)
             {
                 if (lineKey == key)
                 {
                     water = true;
                     break;
                 }
             }
             foreach (string[] keyMult in widthKeysMultipliers)
             {
                 if (key == keyMult[0])
                 {
                     width = float.Parse(Regex.Split(val, @"\s|\D")[0]) * float.Parse(keyMult[1]) * 1.5f;
                 }
             }
         }
         if (road || water)
         {
             line.Width  = width;
             line.Height = road ? 0.3f : 0f;
             line.Type   = road ? Way.WayType.Road : Way.WayType.Water;
             lines.Add(line);
         }
     }
 }
Example #5
0
        void GenerateBoundaries(List <Way> boundaries, List <Way> buildings, List <Way> areas)
        {
            foreach (Way boundary in boundaries)
            {
                XmlNodeList tags = boundary.Node.SelectNodes("tag");
                if (tags.Count == 0)
                {
                    continue;
                }
                if (tags.Count == 1)
                {
                    bool doContinue = false;
                    foreach (string val in terminateIfSingle)
                    {
                        if (val == XmlGetter.GetAttribute <string>("k", tags[0].Attributes) ||
                            val == XmlGetter.GetAttribute <string>("v", tags[0].Attributes))
                        {
                            doContinue = true;
                            break;
                        }
                    }
                    if (doContinue)
                    {
                        continue;
                    }
                }


                bool   isBuilding = false;
                bool   isCampus   = false;
                string name       = null;
                float  height     = 0;

                foreach (XmlNode tag in tags)
                {
                    string key = XmlGetter.GetAttribute <string>("k", tag.Attributes);
                    string val = XmlGetter.GetAttribute <string>("v", tag.Attributes);
                    if (!isBuilding)
                    {
                        foreach (string buildingValue in buildingValues)
                        {
                            if (buildingValue == val)
                            {
                                isBuilding = true;
                                name       = val;
                                break;
                            }
                        }
                        foreach (string buildingKey in buildingKeys)
                        {
                            if (buildingKey == key)
                            {
                                isBuilding = true;
                                break;
                            }
                        }
                    }
                    foreach (string[] keyMult in heightKeysMultipliers)
                    {
                        if (key == keyMult[0])
                        {
                            height     = float.Parse(Regex.Split(val, @"\s|\D")[0]) * float.Parse(keyMult[1]);
                            isBuilding = true;
                        }
                    }
                    foreach (string nameKey in nameKeys)
                    {
                        if (key == nameKey)
                        {
                            name = val;
                        }
                    }
                    if (!isCampus)
                    {
                        foreach (string campusValue in campusValues)
                        {
                            if (val == campusValue)
                            {
                                isCampus = true;
                                break;
                            }
                        }
                    }
                }
                if (isBuilding)
                {
                    if (name == null)
                    {
                        name = "building";
                    }
                    if (height == 0)
                    {
                        height = 5;
                    }
                    boundary.Name   = name;
                    boundary.Height = height;
                    boundary.Type   = isCampus ? Way.WayType.Campus : Way.WayType.Building;
                    buildings.Add(boundary);
                }
                else
                {
                    bool        typeFound = false;
                    Way.WayType type      = Way.WayType.Water;
                    foreach (XmlNode tag in tags)
                    {
                        string key = XmlGetter.GetAttribute <string>("k", tag.Attributes);
                        string val = XmlGetter.GetAttribute <string>("v", tag.Attributes);
                        if (!typeFound)
                        {
                            foreach (string waterValue in waterValues)
                            {
                                if (val == waterValue)
                                {
                                    typeFound = true;
                                    height    = 0f;
                                    if (name == null)
                                    {
                                        name = val;
                                    }
                                    break;
                                }
                            }
                            foreach (string greenValue in greenValues)
                            {
                                if (val == greenValue)
                                {
                                    typeFound = true;
                                    height    = 0.1f;
                                    type      = Way.WayType.Greenery;
                                    if (name == null)
                                    {
                                        name = val;
                                    }
                                    break;
                                }
                            }
                            foreach (string groundValue in groundValues)
                            {
                                if (val == groundValue)
                                {
                                    typeFound = true;
                                    height    = 0.2f;
                                    type      = Way.WayType.Ground;
                                    if (name == null)
                                    {
                                        name = val;
                                    }
                                    break;
                                }
                            }
                            foreach (string roadValue in roadValues)
                            {
                                if (val == roadValue)
                                {
                                    typeFound = true;
                                    height    = 0.3f;
                                    type      = Way.WayType.Road;
                                    if (name == null)
                                    {
                                        name = val;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if (typeFound)
                    {
                        boundary.Name   = name;
                        boundary.Height = height;
                        boundary.Type   = type;
                        areas.Add(boundary);
                    }
                }
            }
        }