public void TestMapCSSArea()
        {
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, new TagsCollection(
                               Tag.Create("area", "yes")), 1, 2, 3, 1));

            // test closed way.
            string css = "area { " +
                         "   fill-color: black; " +
                         "} ";

            // create the projection and scene objects.
            var     mercator = new WebMercator();
            Scene2D scene    = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the projection and scene objects.
            scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                                                                  new MapCSSDictionaryImageSource());

            interpreter.Translate(scene, mercator, source, source.GetWay(1));

            // test the scene contents.
            Assert.AreEqual(1, scene.Count);
            Primitive2D primitive = scene.Get(0);

            Assert.IsInstanceOf <Polygon2D>(primitive);
        }
Example #2
0
        /// <summary>
        /// Renders the primities for the given scene.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        private bool RenderPrimitives(Target2DWrapper <TTarget> target, Scene2D scene, View2D view)
        {
            // TODO: calculate zoom.
            float zoom = (float)view.CalculateZoom(target.Width, target.Height);

            // loop over all primitives in the scene.
            foreach (Scene2DPrimitive scenePrimitive in scene.Get(view, zoom))
            { // the primitive is visible.
                IScene2DPrimitive primitive = scenePrimitive.Primitive;
                if (_cancelFlag)
                {
                    return(false);                    // stop rendering on cancel and return false for an incomplete rendering.
                }

                if (primitive is Point2D)
                {
                    var point = (Point2D)(primitive);
                    this.DrawPoint(target, point.X, point.Y, point.Color,
                                   this.FromPixels(target, view, point.Size));
                }
                else if (primitive is Line2D)
                {
                    var line = (Line2D)(primitive);
                    this.DrawLine(target, line.X, line.Y, line.Color,
                                  this.FromPixels(target, view, line.Width), line.LineJoin, line.Dashes);
                }
                else if (primitive is Polygon2D)
                {
                    var polygon = (Polygon2D)(primitive);
                    this.DrawPolygon(target, polygon.X, polygon.Y, polygon.Color,
                                     this.FromPixels(target, view, polygon.Width), polygon.Fill);
                }
                else if (primitive is Icon2D)
                {
                    var icon = (Icon2D)(primitive);
                    this.DrawIcon(target, icon.X, icon.Y, icon.Image);
                }
                else if (primitive is Image2D)
                {
                    var image = (Image2D)(primitive);
                    image.Tag = this.DrawImage(target, image.Left, image.Top, image.Right, image.Bottom, image.ImageData,
                                               image.Tag);
                }
                else if (primitive is Text2D)
                {
                    var text = (Text2D)(primitive);
                    this.DrawText(target, text.X, text.Y, text.Text, text.Color,
                                  this.FromPixels(target, view, text.Size), text.HaloColor, text.HaloRadius, text.Font);
                }
                else if (primitive is LineText2D)
                {
                    var lineText = (LineText2D)(primitive);
                    this.DrawLineText(target, lineText.X, lineText.Y, lineText.Text, lineText.Color,
                                      this.FromPixels(target, view, lineText.Size), lineText.HaloColor, lineText.HaloRadius, lineText.Font);
                }
            }
            return(true);
        }
        public void TestMapCSSSimpleEval()
        {
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, new TagsCollection(
                               Tag.Create("width", "10")), 1, 2, 3, 1));

            // test closed way.
            string css = "way { " +
                         "   width:  eval(\"tag('width')\"); " +
                         "   color: green; " +
                         "} ";

            // create the projection and scene objects.
            var     mercator = new WebMercator();
            Scene2D scene    = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the projection and scene objects.
            scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                                                                  new MapCSSDictionaryImageSource());

            interpreter.Translate(scene, mercator, source, source.GetWay(1));

            // test the scene contents.
            Assert.AreEqual(1, scene.Count);
            Primitive2D primitive = scene.Get(0);

            Assert.IsInstanceOf <Line2D>(primitive);
            Line2D line = (primitive as Line2D);

            Assert.AreEqual(10, line.Width);
        }
Example #4
0
 /// <summary>
 /// Returns all the object from this layer visible for the given parameters.
 /// </summary>
 /// <param name="zoomFactor"></param>
 /// <param name="view"></param>
 /// <returns></returns>
 internal override IEnumerable <Primitive2D> Get(float zoomFactor, View2D view)
 {
     return(_scene.Get(view, zoomFactor));
 }
        public void TestCanvasJOSMSettingsCSS()
        {
            // create CSS.
            string css = "canvas { " +
                         "background-color: white; " +
                         "default-points: true; " + // adds default points for every node (color: black, size: 2).
                         "default-lines: true; " +  // adds default lines for every way (color: red, width: 1).
                         "} ";

            // create 'test' objects.
            Node node1 = new Node();

            node1.Id        = 1;
            node1.Latitude  = 1;
            node1.Longitude = 1;

            Node node2 = new Node();

            node2.Id        = 2;
            node2.Latitude  = 2;
            node2.Longitude = 2;

            Way way = new Way();

            way.Id    = 1;
            way.Nodes = new List <long>();
            way.Nodes.Add(1);
            way.Nodes.Add(2);

            // create the datasource.
            MemoryDataSource dataSource = new MemoryDataSource();

            dataSource.AddNode(node1);
            dataSource.AddNode(node2);
            dataSource.AddWay(way);

            // create the projection and scene objects.
            var     mercator = new WebMercator();
            Scene2D scene    = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                                                                  new MapCSSDictionaryImageSource());

            interpreter.Translate(scene, mercator, dataSource, node1);
            interpreter.Translate(scene, mercator, dataSource, node2);
            interpreter.Translate(scene, mercator, dataSource, way);

            // test the scene contents.
            Assert.AreEqual(3, scene.Count);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.White).Value, scene.BackColor);

            // test the scene point 1.
            Primitive2D primitive = scene.Get(0);

            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf <Primitive2D>(primitive);
            Point2D pointObject = primitive as Point2D;

            Assert.AreEqual(2, pointObject.Size);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color);
            Assert.AreEqual(mercator.LongitudeToX(1), pointObject.X);
            Assert.AreEqual(mercator.LatitudeToY(1), pointObject.Y);

            // test the scene point 2.
            primitive = scene.Get(1);
            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf <Point2D>(primitive);
            pointObject = primitive as Point2D;
            Assert.AreEqual(2, pointObject.Size);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color);
            Assert.AreEqual(mercator.LongitudeToX(2), pointObject.X);
            Assert.AreEqual(mercator.LatitudeToY(2), pointObject.Y);

            // test the scene line 2.
            primitive = scene.Get(2);
            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf <Line2D>(primitive);
            Line2D line = primitive as Line2D;

            Assert.AreEqual(1, line.Width);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Red).Value, line.Color);
            Assert.IsNotNull(line.X);
            Assert.IsNotNull(line.Y);
            Assert.AreEqual(2, line.X.Length);
            Assert.AreEqual(2, line.Y.Length);
            Assert.AreEqual(mercator.LongitudeToX(1), line.X[0]);
            Assert.AreEqual(mercator.LatitudeToY(1), line.Y[0]);
            Assert.AreEqual(mercator.LongitudeToX(2), line.X[1]);
            Assert.AreEqual(mercator.LatitudeToY(2), line.Y[1]);
        }