コード例 #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="node">Xml node</param>
        public OsmNode(XmlNode node)
        {
            // Get the attribute values
            ID        = GetAttribute <ulong>("id", node.Attributes);
            Latitude  = GetAttribute <float>("lat", node.Attributes);
            Longitude = GetAttribute <float>("lon", node.Attributes);

            // Calculate the position in Unity units
            X = (float)MercatorProjection.lonToX(Longitude);
            Y = (float)MercatorProjection.latToY(Latitude);
        }
コード例 #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="node">Xml node</param>
        public OsmBounds(XmlNode node)
        {
            // Get the values from the node
            MinLat = GetAttribute <float>("minlat", node.Attributes);
            MaxLat = GetAttribute <float>("maxlat", node.Attributes);
            MinLon = GetAttribute <float>("minlon", node.Attributes);
            MaxLon = GetAttribute <float>("maxlon", node.Attributes);

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

            Centre = new Vector3(x, 0, y);
        }
コード例 #3
0
        /// <summary>
        /// Load the OpenMap data resource file.
        /// </summary>
        /// <param name="resourceFile">Path to the resource file. The file must exist.</param>
        public void Read(string resourceFile)
        {
            nodes = new Dictionary <ulong, OsmNode>();
            ways  = new List <OsmWay>();

            var xmlText = File.ReadAllText(resourceFile);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlText);

            SetBounds(doc.SelectSingleNode("/osm/bounds"));
            GetNodes(doc.SelectNodes("/osm/node"));
            GetWays(doc.SelectNodes("/osm/way"));

            float minx = (float)MercatorProjection.lonToX(bounds.MinLon);
            float maxx = (float)MercatorProjection.lonToX(bounds.MaxLon);
            float miny = (float)MercatorProjection.latToY(bounds.MinLat);
            float maxy = (float)MercatorProjection.latToY(bounds.MaxLat);
        }