/// <summary>
 /// Interprets an OSM-object and returns the corresponding geometry.
 /// </summary>
 /// <param name="osmObject"></param>
 /// <returns></returns>
 public abstract GeometryCollection Interpret(CompleteOsmGeo osmObject);
        /// <summary>
        /// Translates OSM objects into basic renderable primitives.
        /// </summary>
        /// <param name="scene">The scene to add primitives to.</param>
        /// <param name="projection">The projection used to convert the objects.</param>
        /// <param name="osmGeo">The osm object.</param>
        /// <returns></returns>
        public override void Translate(Scene2D scene, IProjection projection, CompleteOsmGeo osmGeo)
        {
            // set the scene backcolor.
            scene.BackColor = this.GetCanvasColor().Value;

            if (osmGeo == null) { return; }

            // store the object count.
            int countBefore = scene.Count;

            // interpret the osm-objects.
            switch (osmGeo.Type)
            {
                case CompleteOsmType.Node:
                    this.TranslateNode(scene, projection, osmGeo as CompleteNode);
                    break;
                case CompleteOsmType.Way:
                    this.TranslateWay(scene, projection, osmGeo as CompleteWay);
                    break;
                case CompleteOsmType.Relation:
                    this.TranslateRelation(scene, projection, osmGeo as CompleteRelation);
                    break;
                case CompleteOsmType.ChangeSet:
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            // interpret the osmGeo object and check if it makes up an area.
            GeometryCollection collection = _geometryInterpreter.Interpret(osmGeo);
            foreach (Geometry geometry in collection)
            {
                if (geometry is LineairRing)
                { // a simple lineair ring.
                    this.TranslateLineairRing(scene, projection, geometry as LineairRing);
                }
                else if (geometry is Polygon)
                { // a simple polygon.
                    this.TranslatePolygon(scene, projection, geometry as Polygon);
                }
                else if (geometry is MultiPolygon)
                { // a multipolygon.
                    this.TranslateMultiPolygon(scene, projection, geometry as MultiPolygon);
                }
            }

            // check if any objects have been added to the scene.
            if (scene.Count <= countBefore)
            { // no objects have been added. Apply default styles if needed.
                if (osmGeo.Type == CompleteOsmType.Node &&
                    _mapCSSFile != null &&
                    _mapCSSFile.DefaultPoints)
                { // apply default points style.
                    CompleteNode node = (osmGeo as CompleteNode);
                    scene.AddPoint(this.CalculateSceneLayer(OffsetPoint, 0), float.MinValue, float.MaxValue,
                        projection.LongitudeToX(node.Coordinate.Longitude), projection.LatitudeToY(node.Coordinate.Latitude),
                        SimpleColor.FromKnownColor(KnownColor.Black).Value, 2);
                }
                else if (osmGeo.Type == CompleteOsmType.Way &&
                    _mapCSSFile != null &&
                    _mapCSSFile.DefaultLines)
                { // apply default lines style.
                    CompleteWay way = (osmGeo as CompleteWay);
                    // 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];
                        }
                    }
                    scene.AddLine(this.CalculateSceneLayer(OffsetLine, 0), float.MinValue, float.MaxValue,
                        x, y, SimpleColor.FromKnownColor(KnownColor.Red).Value, 1, LineJoin.Round, null);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a new MapCSS object with a compete osmgeo object.
        /// </summary>
        /// <param name="osmGeoComplete"></param>
        public MapCSSObject(CompleteOsmGeo osmGeoComplete)
        {
            if (osmGeoComplete == null) throw new ArgumentNullException();

            this.OsmGeoComplete = osmGeoComplete;
        }
 /// <summary>
 /// Translates the given OSM objects into corresponding geometries.
 /// </summary>
 /// <param name="projection">The projection to use.</param>
 /// <param name="osmGeo">The osm object.</param>
 /// <param name="scene">The scene to fill with the resulting geometries.</param>
 /// <returns></returns>
 public abstract void Translate(Scene2D scene, IProjection projection, CompleteOsmGeo osmGeo);
Exemple #5
0
 /// <summary>
 /// Creates a new change object.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="obj"></param>
 public CompleteChange(ChangeType type, CompleteOsmGeo obj)
 {
     _type = type;
     _obj  = obj;
 }
Exemple #6
0
 /// <summary>
 /// Creates a new change object.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="obj"></param>
 public CompleteChange(ChangeType type, CompleteOsmGeo obj)
 {
     _type = type;
     _obj = obj;
 }
Exemple #7
0
 /// <summary>
 /// Evaluates the filter against the osm object.
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public bool Evaluate(CompleteOsmGeo obj)
 {
     return this.Evaluate(obj.ToSimple());
 }