예제 #1
0
        /// <summary>
        /// Returns an exact copy of this way.
        ///
        /// WARNING: even the id is copied!
        /// </summary>
        /// <returns></returns>
        public CompleteWay Copy()
        {
            var w = new CompleteWay(this.Id);

            this.CopyTo(w);
            return(w);
        }
        /// <summary>
        /// Compares the two complete objects.
        /// </summary>
        public static void CompareComplete(CompleteWay expected, CompleteWay actual)
        {
            if (expected == null)
            { // ok, if the value is also null.
                Assert.IsNull(actual);
            }
            else
            { // check and compare the value.
                Assert.IsNotNull(actual);
                Assert.AreEqual(expected.Id, actual.Id);
                Assert.AreEqual(expected.ChangeSetId, actual.ChangeSetId);
                Assert.AreEqual(expected.TimeStamp, actual.TimeStamp);
                Assert.AreEqual(expected.User, actual.User);
                Assert.AreEqual(expected.UserId, actual.UserId);
                Assert.AreEqual(expected.Version, actual.Version);
                Assert.AreEqual(expected.Visible, actual.Visible);

                if (expected.Nodes == null)
                { // ok, if the value is also null.
                    Assert.IsNotNull(actual.Nodes);
                }
                else
                { // check and compare the nodes.
                    Assert.AreEqual(expected.Nodes.Count, actual.Nodes.Count);
                    for (int idx = 0; idx < expected.Nodes.Count; idx++)
                    {
                        ComparisonHelpers.CompareComplete(
                            expected.Nodes[idx], actual.Nodes[idx]);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a new way from a SimpleWay.
        /// </summary>
        /// <param name="simpleWay"></param>
        /// <param name="nodeSource"></param>
        /// <returns></returns>
        public static CompleteWay CreateFrom(Way simpleWay, INodeSource nodeSource)
        {
            if (simpleWay == null)
            {
                throw new ArgumentNullException("simpleWay");
            }
            if (nodeSource == null)
            {
                throw new ArgumentNullException("nodeSource");
            }
            if (simpleWay.Id == null)
            {
                throw new Exception("simpleWay.id is null");
            }

            CompleteWay way = Create(simpleWay.Id.Value);

            way.ChangeSetId = simpleWay.ChangeSetId;
            if (simpleWay.Tags != null)
            {
                foreach (Tag pair in simpleWay.Tags)
                {
                    way.Tags.Add(pair);
                }
            }
            if (simpleWay.Nodes != null)
            {
                for (int idx = 0; idx < simpleWay.Nodes.Count; idx++)
                {
                    long nodeId = simpleWay.Nodes[idx];
                    Node node   = nodeSource.GetNode(nodeId);
                    if (node == null)
                    {
                        return(null);
                    }
                    Node completeNode = node;
                    if (completeNode != null)
                    {
                        way.Nodes.Add(completeNode);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            way.TimeStamp = simpleWay.TimeStamp;
            way.User      = simpleWay.UserName;
            way.UserId    = simpleWay.UserId;
            way.Version   = simpleWay.Version.HasValue ? (long)simpleWay.Version.Value : (long?)null;
            way.Visible   = simpleWay.Visible.HasValue && simpleWay.Visible.Value;

            return(way);
        }
예제 #4
0
 /// <summary>
 /// Copies all info in this way to the given way without changing the id.
 /// </summary>
 /// <param name="w"></param>
 public void CopyTo(CompleteWay w)
 {
     foreach (var tag in this.Tags)
     {
         w.Tags.Add(tag.Key, tag.Value);
     }
     w.Nodes.AddRange(this.Nodes);
     w.TimeStamp = this.TimeStamp;
     w.User      = this.User;
     w.UserId    = this.UserId;
     w.Version   = this.Version;
     w.Visible   = this.Visible;
 }
예제 #5
0
        public static CompleteWay CreateFrom(Way simpleWay, INodeSource nodeSource)
        {
            if (simpleWay == null)
            {
                throw new ArgumentNullException("simpleWay");
            }
            if (nodeSource == null)
            {
                throw new ArgumentNullException("nodeSource");
            }
            if (!simpleWay.Id.HasValue)
            {
                throw new Exception("simpleWay.id is null");
            }
            CompleteWay completeWay = CompleteWay.Create(simpleWay.Id.Value);

            completeWay.ChangeSetId = simpleWay.ChangeSetId;
            if (simpleWay.Tags != null)
            {
                foreach (Tag tag in simpleWay.Tags)
                {
                    completeWay.Tags.Add(tag);
                }
            }
            if (simpleWay.Nodes != null)
            {
                for (int index = 0; index < simpleWay.Nodes.Count; ++index)
                {
                    long node1 = simpleWay.Nodes[index];
                    Node node2 = nodeSource.GetNode(node1);
                    if (node2 == null)
                    {
                        return((CompleteWay)null);
                    }
                    Node node3 = node2;
                    if (node3 == null)
                    {
                        return((CompleteWay)null);
                    }
                    completeWay.Nodes.Add(node3);
                }
            }
            completeWay.TimeStamp = simpleWay.TimeStamp;
            completeWay.User      = simpleWay.UserName;
            completeWay.UserId    = simpleWay.UserId;
            completeWay.Version   = simpleWay.Version.HasValue ? new long?((long)simpleWay.Version.Value) : new long?();
            completeWay.Visible   = simpleWay.Visible.HasValue && simpleWay.Visible.Value;
            return(completeWay);
        }
예제 #6
0
        /// <summary>
        /// Creates a new way from a SimpleWay given a stringtable.
        /// </summary>
        /// <param name="table"></param>
        /// <param name="simpleWay"></param>
        /// <param name="nodes"></param>
        /// <returns></returns>
        public static CompleteWay CreateFrom(ObjectTable <string> table, Way simpleWay,
                                             IDictionary <long, Node> nodes)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (simpleWay == null)
            {
                throw new ArgumentNullException("simpleWay");
            }
            if (nodes == null)
            {
                throw new ArgumentNullException("nodes");
            }
            if (simpleWay.Id == null)
            {
                throw new Exception("simpleWay.id is null");
            }

            CompleteWay way = Create(table, simpleWay.Id.Value);

            way.ChangeSetId = simpleWay.ChangeSetId;
            foreach (Tag pair in simpleWay.Tags)
            {
                way.Tags.Add(pair);
            }
            for (int idx = 0; idx < simpleWay.Nodes.Count; idx++)
            {
                long nodeId = simpleWay.Nodes[idx];
                Node node   = null;
                if (nodes.TryGetValue(nodeId, out node))
                {
                    way.Nodes.Add(node);
                }
                else
                {
                    return(null);
                }
            }
            way.TimeStamp = simpleWay.TimeStamp;
            way.User      = simpleWay.UserName;
            way.UserId    = simpleWay.UserId;
            way.Version   = simpleWay.Version.HasValue ? (long)simpleWay.Version.Value : (long?)null;
            way.Visible   = simpleWay.Visible.HasValue && simpleWay.Visible.Value;

            return(way);
        }
예제 #7
0
        public static CompleteWay CreateFrom(ObjectTable <string> table, Way simpleWay, IDictionary <long, Node> nodes)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (simpleWay == null)
            {
                throw new ArgumentNullException("simpleWay");
            }
            if (nodes == null)
            {
                throw new ArgumentNullException("nodes");
            }
            if (!simpleWay.Id.HasValue)
            {
                throw new Exception("simpleWay.id is null");
            }
            CompleteWay completeWay = CompleteWay.Create(table, simpleWay.Id.Value);

            completeWay.ChangeSetId = simpleWay.ChangeSetId;
            foreach (Tag tag in simpleWay.Tags)
            {
                completeWay.Tags.Add(tag);
            }
            for (int index = 0; index < simpleWay.Nodes.Count; ++index)
            {
                long node1 = simpleWay.Nodes[index];
                Node node2 = (Node)null;
                if (!nodes.TryGetValue(node1, out node2))
                {
                    return((CompleteWay)null);
                }
                completeWay.Nodes.Add(node2);
            }
            completeWay.TimeStamp = simpleWay.TimeStamp;
            completeWay.User      = simpleWay.UserName;
            completeWay.UserId    = simpleWay.UserId;
            completeWay.Version   = simpleWay.Version.HasValue ? new long?((long)simpleWay.Version.Value) : new long?();
            completeWay.Visible   = simpleWay.Visible.HasValue && simpleWay.Visible.Value;
            return(completeWay);
        }
예제 #8
0
        public IList <GeoCoordinate> GetCoordinates()
        {
            List <GeoCoordinate> geoCoordinateList = new List <GeoCoordinate>();

            for (int index = 0; index < this.Members.Count; ++index)
            {
                if (this.Members[index].Member is Node)
                {
                    Node member = this.Members[index].Member as Node;
                    geoCoordinateList.Add(member.Coordinate);
                }
                else if (this.Members[index].Member is CompleteWay)
                {
                    CompleteWay member = this.Members[index].Member as CompleteWay;
                    geoCoordinateList.AddRange((IEnumerable <GeoCoordinate>)member.GetCoordinates());
                }
                else if (this.Members[index].Member is CompleteRelation)
                {
                    CompleteRelation member = this.Members[index].Member as CompleteRelation;
                    geoCoordinateList.AddRange((IEnumerable <GeoCoordinate>)member.GetCoordinates());
                }
            }
            return((IList <GeoCoordinate>)geoCoordinateList);
        }
 /// <summary>
 /// Adds a new way.
 /// </summary>
 /// <param name="way"></param>
 public override void AddWay(CompleteWay way)
 {
     _mapCSSInterpreter.Translate(_scene, _projection, way);
 }
예제 #10
0
        public static CompleteRelation CreateFrom(Relation simpleRelation, IOsmGeoSource osmGeoSource, IDictionary <long, CompleteWay> ways, IDictionary <long, CompleteRelation> relations)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (osmGeoSource == null)
            {
                throw new ArgumentNullException("osmGeoSource");
            }
            if (!simpleRelation.Id.HasValue)
            {
                throw new Exception("simpleRelation.Id is null");
            }
            CompleteRelation completeRelation1 = CompleteRelation.Create(simpleRelation.Id.Value);

            completeRelation1.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (Tag tag in simpleRelation.Tags)
            {
                completeRelation1.Tags.Add(tag);
            }
            long?nullable1;

            for (int index = 0; index < simpleRelation.Members.Count; ++index)
            {
                nullable1 = simpleRelation.Members[index].MemberId;
                long   num        = nullable1.Value;
                string memberRole = simpleRelation.Members[index].MemberRole;
                CompleteRelationMember completeRelationMember = new CompleteRelationMember();
                completeRelationMember.Role = memberRole;
                switch (simpleRelation.Members[index].MemberType.Value)
                {
                case OsmGeoType.Node:
                    Node node = osmGeoSource.GetNode(num);
                    if (node == null)
                    {
                        return((CompleteRelation)null);
                    }
                    completeRelationMember.Member = (ICompleteOsmGeo)node;
                    break;

                case OsmGeoType.Way:
                    CompleteWay from1;
                    if (!ways.TryGetValue(num, out from1))
                    {
                        Way way = osmGeoSource.GetWay(num);
                        if (way != null)
                        {
                            from1 = CompleteWay.CreateFrom(way, (INodeSource)osmGeoSource);
                        }
                    }
                    if (!((CompleteOsmBase)from1 != (CompleteOsmBase)null))
                    {
                        return((CompleteRelation)null);
                    }
                    completeRelationMember.Member = (ICompleteOsmGeo)from1;
                    break;

                case OsmGeoType.Relation:
                    CompleteRelation from2;
                    if (!relations.TryGetValue(num, out from2))
                    {
                        Relation relation = osmGeoSource.GetRelation(num);
                        if (relation != null)
                        {
                            from2 = CompleteRelation.CreateFrom(relation, osmGeoSource);
                        }
                    }
                    if (!((CompleteOsmBase)from2 != (CompleteOsmBase)null))
                    {
                        return((CompleteRelation)null);
                    }
                    completeRelationMember.Member = (ICompleteOsmGeo)from2;
                    break;
                }
                completeRelation1.Members.Add(completeRelationMember);
            }
            completeRelation1.TimeStamp = simpleRelation.TimeStamp;
            completeRelation1.User      = simpleRelation.UserName;
            completeRelation1.UserId    = simpleRelation.UserId;
            CompleteRelation completeRelation2 = completeRelation1;
            long?            nullable2;

            if (!simpleRelation.Version.HasValue)
            {
                nullable1 = new long?();
                nullable2 = nullable1;
            }
            else
            {
                nullable2 = new long?((long)simpleRelation.Version.Value);
            }
            completeRelation2.Version = nullable2;
            completeRelation1.Visible = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;
            return(completeRelation1);
        }
예제 #11
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <param name="simpleRelation"></param>
        /// <param name="osmGeoSource"></param>
        /// <param name="ways"></param>
        /// <param name="relations"></param>
        /// <returns></returns>
        public static CompleteRelation CreateFrom(Relation simpleRelation, IOsmGeoSource osmGeoSource,
                                                  IDictionary <long, CompleteWay> ways,
                                                  IDictionary <long, CompleteRelation> relations)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (osmGeoSource == null)
            {
                throw new ArgumentNullException("osmGeoSource");
            }
            if (simpleRelation.Id == null)
            {
                throw new Exception("simpleRelation.Id is null");
            }

            CompleteRelation relation = Create(simpleRelation.Id.Value);

            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (Tag pair in simpleRelation.Tags)
            {
                relation.Tags.Add(pair);
            }
            for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
            {
                long   memberId = simpleRelation.Members[idx].MemberId.Value;
                string role     = simpleRelation.Members[idx].MemberRole;

                var member = new CompleteRelationMember();
                member.Role = role;
                switch (simpleRelation.Members[idx].MemberType.Value)
                {
                case OsmGeoType.Node:
                    Node simpleNode = osmGeoSource.GetNode(memberId);
                    if (simpleNode != null)
                    {
                        member.Member = simpleNode;
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Way:
                    CompleteWay completeWay;
                    if (!ways.TryGetValue(memberId, out completeWay))
                    {
                        Way simpleWay = osmGeoSource.GetWay(memberId);
                        if (simpleWay != null)
                        {
                            completeWay = CompleteWay.CreateFrom(simpleWay, osmGeoSource);
                        }
                    }
                    if (completeWay != null)
                    {
                        member.Member = completeWay;
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Relation:
                    CompleteRelation completeRelation;
                    if (!relations.TryGetValue(memberId, out completeRelation))
                    {
                        Relation simpleRelationMember = osmGeoSource.GetRelation(memberId);
                        if (simpleRelationMember != null)
                        {
                            completeRelation = CompleteRelation.CreateFrom(simpleRelationMember, osmGeoSource);
                        }
                    }
                    if (completeRelation != null)
                    {
                        member.Member = completeRelation;
                    }
                    else
                    {
                        return(null);
                    }
                    break;
                }
                relation.Members.Add(member);
            }
            relation.TimeStamp = simpleRelation.TimeStamp;
            relation.User      = simpleRelation.UserName;
            relation.UserId    = simpleRelation.UserId;
            relation.Version   = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null;
            relation.Visible   = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;

            return(relation);
        }
예제 #12
0
        /// <summary>
        /// Creates a new relation from a SimpleRelation.
        /// </summary>
        /// <param name="table"></param>
        /// <param name="simpleRelation"></param>
        /// <param name="nodes"></param>
        /// <param name="ways"></param>
        /// <param name="relations"></param>
        /// <returns></returns>
        public static CompleteRelation CreateFrom(ObjectTable <string> table, Relation simpleRelation,
                                                  IDictionary <long, Node> nodes,
                                                  IDictionary <long, CompleteWay> ways,
                                                  IDictionary <long, CompleteRelation> relations)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (nodes == null)
            {
                throw new ArgumentNullException("nodes");
            }
            if (ways == null)
            {
                throw new ArgumentNullException("ways");
            }
            if (relations == null)
            {
                throw new ArgumentNullException("relations");
            }
            if (simpleRelation.Id == null)
            {
                throw new Exception("simpleRelation.Id is null");
            }

            CompleteRelation relation = Create(table, simpleRelation.Id.Value);

            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (Tag pair in simpleRelation.Tags)
            {
                relation.Tags.Add(pair);
            }
            for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
            {
                long   memberId = simpleRelation.Members[idx].MemberId.Value;
                string role     = simpleRelation.Members[idx].MemberRole;

                var member = new CompleteRelationMember();
                member.Role = role;
                switch (simpleRelation.Members[idx].MemberType.Value)
                {
                case OsmGeoType.Node:
                    Node node = null;
                    if (nodes.TryGetValue(memberId, out node))
                    {
                        member.Member = node;
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Way:
                    CompleteWay way = null;
                    if (ways.TryGetValue(memberId, out way))
                    {
                        member.Member = way;
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Relation:
                    CompleteRelation relationMember = null;
                    if (relations.TryGetValue(memberId, out relationMember))
                    {
                        member.Member = relationMember;
                    }
                    else
                    {
                        return(null);
                    }
                    break;
                }
                relation.Members.Add(member);
            }
            relation.TimeStamp = simpleRelation.TimeStamp;
            relation.User      = simpleRelation.UserName;
            relation.UserId    = simpleRelation.UserId;
            relation.Version   = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null;
            relation.Visible   = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;

            return(relation);
        }
예제 #13
0
        /// <summary>
        /// Translates a way.
        /// </summary>
        /// <param name="scene">The scene to add primitives to.</param>
        /// <param name="projection">The projection used to convert the objects.</param>
        /// <param name="way"></param>
        private void TranslateWay(Scene2D scene, IProjection projection, CompleteWay way)
        {
            // build the rules.
            List<MapCSSRuleProperties> rules =
                this.BuildRules(new MapCSSObject(way));

            // validate what's there.
            if (rules.Count == 0)
            {
                return;
            }

            // get x/y.
            double[] x = null, y = null;
            if (x == null)
            { // pre-calculate x/y.
                x = new double[way.Nodes.Count];
                y = new double[way.Nodes.Count];
                for (int idx = 0; idx < way.Nodes.Count; idx++)
                {
                    x[idx] = projection.LongitudeToX(
                        way.Nodes[idx].Coordinate.Longitude);
                    y[idx] = projection.LatitudeToY(
                        way.Nodes[idx].Coordinate.Latitude);
                }

                // simplify.
                if (x.Length > 2)
                {
                    double[][] simplified = SimplifyCurve.Simplify(new double[][] {x, y}, 0.0001);
                    x = simplified[0];
                    y = simplified[1];
                }
            }

            // add the z-index.
            foreach (var rule in rules)
            {
                float minZoom = (float)projection.ToZoomFactor(rule.MinZoom);
                float maxZoom = (float)projection.ToZoomFactor(rule.MaxZoom);

                int zIndex ;
                if (!rule.TryGetProperty<int>("zIndex", out zIndex))
                {
                    zIndex = 0;
                }

                // interpret the results.
                if (x != null)
                { // there is a valid interpretation of this way.
                    int color;
                    if (way.IsOfType(MapCSSTypes.Area))
                    { // the way is an area. check if it can be rendered as an area.
                        int fillColor;
                        if (rule.TryGetProperty("fillColor", out fillColor))
                        { // render as an area.
                            scene.AddPolygon(this.CalculateSceneLayer(OffsetArea, zIndex), minZoom, maxZoom, x, y, fillColor, 1, true);
                            if (rule.TryGetProperty("color", out color))
                            {
                                scene.AddPolygon(this.CalculateSceneLayer(OffsetCasing, zIndex), minZoom, maxZoom, x, y, color, 1, false);
                            }
                        }
                    }

                    // the way has to rendered as a line.
                    LineJoin lineJoin;
                    if (!rule.TryGetProperty("lineJoin", out lineJoin))
                    {
                        lineJoin = LineJoin.Miter;
                    }
                    int[] dashes;
                    if (!rule.TryGetProperty("dashes", out dashes))
                    {
                        dashes = null;
                    }
                    if (rule.TryGetProperty("color", out color))
                    {
                        float casingWidth;
                        int casingColor;
                        if (!rule.TryGetProperty("casingWidth", out casingWidth))
                        {
                            casingWidth = 0;
                        }
                        if(!rule.TryGetProperty("casingColor", out casingColor))
                        { // casing: use the casing layer.
                            casingColor = -1;
                        }
                        float width;
                        if (!rule.TryGetProperty("width", out width))
                        {
                            width = 1;
                        }
                        if (casingWidth > 0)
                        { // adds the casing
                            scene.AddLine(this.CalculateSceneLayer(OffsetCasing, zIndex),
                                minZoom, maxZoom, x, y, casingColor, width + (casingWidth * 2), lineJoin, dashes);
                        }
                        if (dashes == null)
                        { // dashes not set, use line offset.
                            scene.AddLine(this.CalculateSceneLayer(OffsetLine, zIndex),
                                minZoom, maxZoom, x, y, color, width, lineJoin, dashes);
                        }
                        else
                        { // dashes set, use line pattern offset.
                            scene.AddLine(this.CalculateSceneLayer(OffsetLinePattern, zIndex),
                                minZoom, maxZoom, x, y, color, width, lineJoin, dashes);
                        }

                        int textColor;
                        int fontSize;
                        string nameTag;
                        if (!rule.TryGetProperty("fontSize", out fontSize))
                        {
                            fontSize = 10;
                        }
                        if (rule.TryGetProperty("text", out nameTag) &&
                            rule.TryGetProperty("textColor", out textColor))
                        {
                            int haloColor;
                            int? haloColorNullable = null;
                            if (rule.TryGetProperty("textHaloColor", out haloColor))
                            {
                                haloColorNullable = haloColor;
                            }
                            int haloRadius;
                            int? haloRadiusNullable = null;
                            if (rule.TryGetProperty("textHaloRadius", out haloRadius))
                            {
                                haloRadiusNullable = haloRadius;
                            }
                            string name;
                            if (way.Tags.TryGetValue(nameTag, out name))
                            {
                                scene.AddTextLine(this.CalculateSceneLayer(OffsetLineText, zIndex),
                                    minZoom, maxZoom, x, y, textColor, fontSize, name, haloColorNullable, haloRadiusNullable);
                            }
                        }
                    }
                }
            }
        }
예제 #14
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <param name="simpleRelation"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public static CompleteRelation CreateFrom(Relation simpleRelation, IDataSourceReadOnly cache)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (simpleRelation.Id == null)
            {
                throw new Exception("simpleRelation.Id is null");
            }

            CompleteRelation relation = Create(simpleRelation.Id.Value);

            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (Tag pair in simpleRelation.Tags)
            {
                relation.Tags.Add(pair);
            }
            for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
            {
                long   memberId = simpleRelation.Members[idx].MemberId.Value;
                string role     = simpleRelation.Members[idx].MemberRole;

                var member = new CompleteRelationMember();
                member.Role = role;
                switch (simpleRelation.Members[idx].MemberType.Value)
                {
                case OsmGeoType.Node:
                    Node simpleNode = cache.GetNode(memberId);
                    if (simpleNode != null)
                    {
                        member.Member = CompleteNode.CreateFrom(simpleNode);
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Way:
                    Way simpleWay = cache.GetWay(memberId);
                    if (simpleWay != null)
                    {
                        member.Member = CompleteWay.CreateFrom(simpleWay, cache);
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Relation:
                    Relation simpleRelationMember = cache.GetRelation(memberId);
                    if (simpleRelationMember != null)
                    {
                        member.Member = CompleteRelation.CreateFrom(simpleRelationMember, cache);
                    }
                    else
                    {
                        return(null);
                    }
                    break;
                }
                relation.Members.Add(member);
            }
            relation.TimeStamp = simpleRelation.TimeStamp;
            relation.User      = simpleRelation.UserName;
            relation.UserId    = simpleRelation.UserId;
            relation.Version   = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null;
            relation.Visible   = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;

            return(relation);
        }
예제 #15
0
 /// <summary>
 /// Adds a way to the target.
 /// </summary>
 /// <param name="way"></param>
 public abstract void AddWay(CompleteWay way);
예제 #16
0
 /// <summary>
 /// Copies all info in this way to the given way without changing the id.
 /// </summary>
 /// <param name="w"></param>
 public void CopyTo(CompleteWay w)
 {
     foreach (var tag in this.Tags)
     {
         w.Tags.Add(tag.Key, tag.Value);
     }
     w.Nodes.AddRange(this.Nodes);
     w.TimeStamp = this.TimeStamp;
     w.User = this.User;
     w.UserId = this.UserId;
     w.Version = this.Version;
     w.Visible = this.Visible;
 }
예제 #17
0
        /// <summary>
        /// Translates a way.
        /// </summary>
        /// <param name="scene">The scene to add primitives to.</param>
        /// <param name="projection">The projection used to convert the objects.</param>
        /// <param name="way"></param>
        /// <param name="relevantTags"></param>
        private bool TranslateWay(Scene2D scene, IProjection projection, CompleteWay way, TagsCollectionBase relevantTags)
        {
            // build the rules.
            List<MapCSSRuleProperties> rules = null;
            if (!_succesfullWays.TryGetValue(relevantTags, out rules))
            {
                rules = this.BuildRules(new MapCSSObject(way));
                _succesfullWays.Add(relevantTags, rules);
            }

            // validate what's there.
            if (rules.Count == 0)
            {
                return false;
            }

            bool success = false;

            // get x/y.
            double[] x = null, y = null;
            if (x == null)
            { // pre-calculate x/y.
                x = new double[way.Nodes.Count];
                y = new double[way.Nodes.Count];
                for (int idx = 0; idx < way.Nodes.Count; idx++)
                {
                    x[idx] = projection.LongitudeToX(
                        way.Nodes[idx].Coordinate.Longitude);
                    y[idx] = projection.LatitudeToY(
                        way.Nodes[idx].Coordinate.Latitude);
                }

                // simplify.
                if (x.Length > 2)
                {
                    double[][] simplified = SimplifyCurve.Simplify(new double[][] {x, y}, 0.0001);
                    x = simplified[0];
                    y = simplified[1];
                }
            }

            // add the z-index.
            foreach (var rule in rules)
            {
                float minZoom = (float)projection.ToZoomFactor(rule.MinZoom);
                float maxZoom = (float)projection.ToZoomFactor(rule.MaxZoom);

                int zIndex ;
                if (!rule.TryGetProperty<int>("zIndex", out zIndex))
                {
                    zIndex = 0;
                }

                // interpret the results.
                if (x != null &&
                    x.Length > 1)
                { // there is a valid interpretation of this way.
                    int color;
                    bool renderAsLine = true;
                    if (way.IsOfType(MapCSSTypes.Area))
                    { // the way is an area. check if it can be rendered as an area.
                        int fillColor;
                        if (rule.TryGetProperty("fillColor", out fillColor))
                        { // render as an area.
                            uint? pointsId = scene.AddPoints(x, y);
                            if (pointsId.HasValue)
                            {
                                scene.AddStylePolygon(pointsId.Value, this.CalculateSceneLayer(OffsetArea, zIndex), minZoom, maxZoom, fillColor, 1, true);
                                success = true;
                                if (rule.TryGetProperty("color", out color))
                                {
                                    scene.AddStylePolygon(pointsId.Value, this.CalculateSceneLayer(OffsetCasing, zIndex), minZoom, maxZoom, color, 1, false);
                                    success = true;
                                }
                            }
                            renderAsLine = false; // was validly rendered als a line.
                        }
                    }

                    if (renderAsLine)
                    { // was not rendered as an area.
                        // the way has to rendered as a line.
                        LineJoin lineJoin;
                        if (!rule.TryGetProperty("lineJoin", out lineJoin))
                        {
                            lineJoin = LineJoin.Miter;
                        }
                        int[] dashes;
                        if (!rule.TryGetProperty("dashes", out dashes))
                        {
                            dashes = null;
                        }
                        if (rule.TryGetProperty("color", out color))
                        {
                            float casingWidth;
                            int casingColor;
                            if (!rule.TryGetProperty("casingWidth", out casingWidth))
                            {
                                casingWidth = 0;
                            }
                            if (!rule.TryGetProperty("casingColor", out casingColor))
                            { // casing: use the casing layer.
                                casingColor = -1;
                            }
                            float width;
                            if (!rule.TryGetProperty("width", out width))
                            {
                                width = 1;
                            }
                            uint? pointsId = scene.AddPoints(x, y);
                            success = true;
                            if (pointsId.HasValue)
                            {
                                if (casingWidth > 0)
                                { // adds the casing
                                    scene.AddStyleLine(pointsId.Value, this.CalculateSceneLayer(OffsetCasing, zIndex),
                                        minZoom, maxZoom, casingColor, width + (casingWidth * 2), lineJoin, dashes);
                                }
                                if (dashes == null)
                                { // dashes not set, use line offset.
                                    scene.AddStyleLine(pointsId.Value, this.CalculateSceneLayer(OffsetLine, zIndex),
                                        minZoom, maxZoom, color, width, lineJoin, dashes);
                                }
                                else
                                { // dashes set, use line pattern offset.
                                    scene.AddStyleLine(pointsId.Value, this.CalculateSceneLayer(OffsetLinePattern, zIndex),
                                        minZoom, maxZoom, color, width, lineJoin, dashes);
                                }

                                int textColor;
                                int fontSize;
                                string nameTag;
                                if (!rule.TryGetProperty("fontSize", out fontSize))
                                {
                                    fontSize = 10;
                                }
                                if (rule.TryGetProperty("text", out nameTag) &&
                                    rule.TryGetProperty("textColor", out textColor))
                                {
                                    int haloColor;
                                    int? haloColorNullable = null;
                                    if (rule.TryGetProperty("textHaloColor", out haloColor))
                                    {
                                        haloColorNullable = haloColor;
                                    }
                                    int haloRadius;
                                    int? haloRadiusNullable = null;
                                    if (rule.TryGetProperty("textHaloRadius", out haloRadius))
                                    {
                                        haloRadiusNullable = haloRadius;
                                    }
                                    string fontFamily;
                                    if (!rule.TryGetProperty("fontFamily", out fontFamily))
                                    {
                                        fontFamily = "Arial"; // just some default font.
                                    }
                                    string name;
                                    if (way.Tags.TryGetValue(nameTag, out name))
                                    {
                                        scene.AddStyleLineText(pointsId.Value, this.CalculateSceneLayer(OffsetLineText, zIndex),
                                            minZoom, maxZoom, textColor, fontSize, name, fontFamily, haloColorNullable, haloRadiusNullable);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                { // don't report as an error when no nodes.
                    success = true;
                }
            }

            if(!success)
            { // make sure this sucess is stored.
                _succesfullWays[relevantTags] = null;
            }

            return success;
        }
예제 #18
0
        public static CompleteRelation CreateFrom(ObjectTable <string> table, Relation simpleRelation, IDictionary <long, Node> nodes, IDictionary <long, CompleteWay> ways, IDictionary <long, CompleteRelation> relations)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (nodes == null)
            {
                throw new ArgumentNullException("nodes");
            }
            if (ways == null)
            {
                throw new ArgumentNullException("ways");
            }
            if (relations == null)
            {
                throw new ArgumentNullException("relations");
            }
            if (!simpleRelation.Id.HasValue)
            {
                throw new Exception("simpleRelation.Id is null");
            }
            CompleteRelation completeRelation1 = CompleteRelation.Create(table, simpleRelation.Id.Value);

            completeRelation1.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (Tag tag in simpleRelation.Tags)
            {
                completeRelation1.Tags.Add(tag);
            }
            long?nullable1;

            for (int index = 0; index < simpleRelation.Members.Count; ++index)
            {
                nullable1 = simpleRelation.Members[index].MemberId;
                long   key        = nullable1.Value;
                string memberRole = simpleRelation.Members[index].MemberRole;
                CompleteRelationMember completeRelationMember = new CompleteRelationMember();
                completeRelationMember.Role = memberRole;
                switch (simpleRelation.Members[index].MemberType.Value)
                {
                case OsmGeoType.Node:
                    Node node = (Node)null;
                    if (!nodes.TryGetValue(key, out node))
                    {
                        return((CompleteRelation)null);
                    }
                    completeRelationMember.Member = (ICompleteOsmGeo)node;
                    break;

                case OsmGeoType.Way:
                    CompleteWay completeWay = (CompleteWay)null;
                    if (!ways.TryGetValue(key, out completeWay))
                    {
                        return((CompleteRelation)null);
                    }
                    completeRelationMember.Member = (ICompleteOsmGeo)completeWay;
                    break;

                case OsmGeoType.Relation:
                    CompleteRelation completeRelation2 = (CompleteRelation)null;
                    if (!relations.TryGetValue(key, out completeRelation2))
                    {
                        return((CompleteRelation)null);
                    }
                    completeRelationMember.Member = (ICompleteOsmGeo)completeRelation2;
                    break;
                }
                completeRelation1.Members.Add(completeRelationMember);
            }
            completeRelation1.TimeStamp = simpleRelation.TimeStamp;
            completeRelation1.User      = simpleRelation.UserName;
            completeRelation1.UserId    = simpleRelation.UserId;
            CompleteRelation completeRelation3 = completeRelation1;
            ulong?           version           = simpleRelation.Version;
            long?            nullable2;

            if (!version.HasValue)
            {
                nullable1 = new long?();
                nullable2 = nullable1;
            }
            else
            {
                version   = simpleRelation.Version;
                nullable2 = new long?((long)version.Value);
            }
            completeRelation3.Version = nullable2;
            completeRelation1.Visible = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;
            return(completeRelation1);
        }
 /// <summary>
 /// Adds a new way.
 /// </summary>
 /// <param name="way"></param>
 public override void AddWay(CompleteWay way)
 {
     if (way.Id == 198214128)
     {
         System.Diagnostics.Debug.WriteLine("");
     }
     _mapCSSInterpreter.Translate(_scene, _projection, way);
 }
예제 #20
0
 /// <summary>
 /// Returns an exact copy of this way.
 /// 
 /// WARNING: even the id is copied!
 /// </summary>
 /// <returns></returns>
 public CompleteWay Copy()
 {
     var w = new CompleteWay(this.Id);
     this.CopyTo(w);
     return w;
 }
예제 #21
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <returns></returns>
        public static CompleteRelation CreateFrom(Relation simpleRelation, IOsmGeoSource osmGeoSource)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (osmGeoSource == null)
            {
                throw new ArgumentNullException("osmGeoSource");
            }
            if (simpleRelation.Id == null)
            {
                throw new Exception("simpleRelation.Id is null");
            }

            var relation = Create(simpleRelation.Id.Value);

            relation.ChangeSetId = simpleRelation.ChangeSetId;
            if (simpleRelation.Tags != null)
            {
                foreach (var pair in simpleRelation.Tags)
                {
                    relation.Tags.Add(pair);
                }
            }
            if (simpleRelation.Members != null)
            {
                for (var idx = 0; idx < simpleRelation.Members.Count; idx++)
                {
                    var memberId = simpleRelation.Members[idx].MemberId.Value;
                    var role     = simpleRelation.Members[idx].MemberRole;
                    var member   = new CompleteRelationMember();
                    member.Role = role;
                    switch (simpleRelation.Members[idx].MemberType.Value)
                    {
                    case OsmGeoType.Node:
                        var simpleNode = osmGeoSource.GetNode(memberId);
                        if (simpleNode == null)
                        {
                            return(null);
                        }
                        var completeNode = simpleNode;
                        if (completeNode != null)
                        {
                            member.Member = completeNode;
                        }
                        else
                        {
                            return(null);
                        }
                        break;

                    case OsmGeoType.Way:
                        var simpleWay = osmGeoSource.GetWay(memberId);
                        if (simpleWay == null)
                        {
                            return(null);
                        }
                        var completeWay = CompleteWay.CreateFrom(simpleWay, osmGeoSource);
                        if (completeWay != null)
                        {
                            member.Member = completeWay;
                        }
                        else
                        {
                            return(null);
                        }
                        break;

                    case OsmGeoType.Relation:
                        var simpleRelationMember = osmGeoSource.GetRelation(memberId);
                        if (simpleRelationMember == null)
                        {
                            return(null);
                        }
                        var completeRelation = CompleteRelation.CreateFrom(simpleRelationMember, osmGeoSource);
                        if (completeRelation != null)
                        {
                            member.Member = completeRelation;
                        }
                        else
                        {
                            return(null);
                        }
                        break;
                    }
                    relation.Members.Add(member);
                }
            }
            relation.TimeStamp = simpleRelation.TimeStamp;
            relation.User      = simpleRelation.UserName;
            relation.UserId    = simpleRelation.UserId;
            relation.Version   = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null;
            relation.Visible   = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;
            return(relation);
        }