Ejemplo n.º 1
0
        public void TestCanvasSettingsCSS()
        {
            // create CSS.
            string css = "canvas { " +
                         "fill-color: green; " +
                         "} ";

            // 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(0, scene.Count);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Green).Value, scene.BackColor);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public void TestMapCSSClosedWay()
        { // tests map css interpretation of a closed way marked as an area.
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, new SimpleTagsCollection(
                               Tag.Create("area", "yes")), 1, 2, 3, 1));

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

            // create the projection and scene objects.
            var     mercator = new WebMercator();
            Scene2D scene    = new Scene2DSimple();

            // 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);
            List <IScene2DPrimitive> primitives = scene.Get(0);

            Assert.IsNotNull(primitives);
            Assert.AreEqual(1, primitives.Count);
            IScene2DPrimitive primitive = primitives[0];

            Assert.IsInstanceOf <Polygon2D>(primitive);
        }
Ejemplo n.º 4
0
        public void TestEmptyCSS()
        {
            // 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 Scene2DSimple();

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(string.Empty,
                                                                  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(0, scene.Count);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, scene.BackColor);
        }
Ejemplo n.º 5
0
        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 SimpleTagsCollection(
                               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 Scene2DSimple();

            // create the projection and scene objects.
            scene = new Scene2DSimple();

            // 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);
            List <IScene2DPrimitive> primitives = scene.Get(0);

            Assert.IsNotNull(primitives);
            Assert.AreEqual(1, primitives.Count);
            IScene2DPrimitive primitive = primitives[0];

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

            Assert.AreEqual(10, line.Width);
        }
        public void Scene2DSimpleSerializeDeserializeTest()
        {
            // create the MapCSS image source.
            var imageSource = new MapCSSDictionaryImageSource();

            // load mapcss style interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.UI.Test.Unittests.Data.MapCSS.test.mapcss"),
                imageSource);

            // initialize the data source.
            var xmlSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.UI.Test.Unittests.Data.test.osm"));
            IEnumerable <OsmGeo> dataSource = xmlSource;
            MemoryDataSource     source     = MemoryDataSource.CreateFrom(xmlSource);

            // get data.
            var scene            = new Scene2DSimple();
            var projection       = new WebMercator();
            GeoCoordinateBox box = null;

            foreach (var osmGeo in dataSource)
            {
                CompleteOsmGeo completeOsmGeo = null;
                switch (osmGeo.Type)
                {
                case OsmGeoType.Node:
                    completeOsmGeo = CompleteNode.CreateFrom(osmGeo as Node);
                    break;

                case OsmGeoType.Way:
                    completeOsmGeo = CompleteWay.CreateFrom(osmGeo as Way,
                                                            source);
                    break;

                case OsmGeoType.Relation:
                    completeOsmGeo = CompleteRelation.CreateFrom(osmGeo as Relation,
                                                                 source);
                    break;
                }

                // update box.
                if (completeOsmGeo != null)
                {
                    if (box == null)
                    {
                        box = completeOsmGeo.BoundingBox;
                    }
                    else if (completeOsmGeo.BoundingBox != null)
                    {
                        box = box + completeOsmGeo.BoundingBox;
                    }
                }

                // translate each object into scene object.
                mapCSSInterpreter.Translate(scene, projection, source, osmGeo as OsmGeo);
            }

            // create the stream.
            var stream = new MemoryStream();

            scene.Serialize(stream, false);

            // deserialize the stream.
            IScene2DPrimitivesSource sceneSource = Scene2DSimple.Deserialize(stream, false);

            if (box != null)
            {
                // query both and get the same results.
                int counter = 100;
                var rand    = new Random();
                while (counter > 0)
                {
                    var queryBox = new GeoCoordinateBox(
                        box.GenerateRandomIn(rand),
                        box.GenerateRandomIn(rand));
                    var    zoomFactor = (float)projection.ToZoomFactor(15);
                    View2D testView   = View2D.CreateFromBounds(
                        projection.LatitudeToY(queryBox.MaxLat),
                        projection.LongitudeToX(queryBox.MinLon),
                        projection.LatitudeToY(queryBox.MinLat),
                        projection.LongitudeToX(queryBox.MaxLon));
                    var testScene = new Scene2DSimple();
                    sceneSource.Get(testScene, testView, zoomFactor);

//                    var resultIndex = new HashSet<Scene2DPrimitive>(testScene.Get(testView, zoomFactor));
//                    var resultReference = new HashSet<Scene2DPrimitive>(scene.Get(testView, zoomFactor));

                    //Assert.AreEqual(resultReference.Count, resultIndex.Count);
                    //foreach (var data in resultIndex)
                    //{
                    //    Assert.IsTrue(resultReference.Contains(data));
                    //}
                    //foreach (var data in resultReference)
                    //{
                    //    Assert.IsTrue(resultIndex.Contains(data));
                    //}
                    counter--;
                }
            }
        }
Ejemplo n.º 7
0
        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]);
        }