Exemple #1
0
        /// <summary>
        /// Adds the polygon.
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="maxZoom"></param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="width">Width.</param>
        /// <returns>The polygon.</returns>
        /// <param name="minZoom">Minimum zoom.</param>
        /// <param name="fill">If set to <c>true</c> fill.</param>
        public override uint AddPolygon(int layer, float minZoom, float maxZoom, double[] x, double[] y, int color, double width,
                                        bool fill)
        {         // add the polygon but simplify it for higher zoom levels.
            float currentMaxZoom = float.MaxValue;

            for (int idx = 0; idx < _zoomLevelCutoffs.Count; idx++)
            {
                float currentMinZoom = _zoomLevelCutoffs [idx];
                if (!(currentMinZoom >= maxZoom) && !(currentMaxZoom < minZoom))
                {
                    float thisMinZoom = System.Math.Max(currentMinZoom, minZoom);
                    float thisMaxZoom = System.Math.Min(currentMaxZoom, maxZoom);

                    // simplify the algorithm.
                    double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y },
                                                                                            this.CalculateSimplificationEpsilon(thisMaxZoom));

                    if (simplified[0].Length > 2 &&
                        this.CalculateSimplificationSurfaceCondition(currentMaxZoom, x, y))
                    {
                        // add to the scene.
                        if (_scenes[idx] == null)
                        {
                            _scenes[idx] = new Scene2DSimple();
                        }
                        _scenes[idx].AddPolygon(thisMinZoom, thisMaxZoom, simplified[0], simplified[1], color, width, fill);
                    }
                }
                currentMaxZoom = currentMinZoom;                 // move to the next cutoff.
            }
            return(0);
        }
Exemple #2
0
        /// <summary>
        /// Adds a text along a line to this scene.
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="minZoom"></param>
        /// <param name="maxZoom"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="color"></param>
        /// <param name="font_size"></param>
        /// <param name="text"></param>
        /// <returns>The text line.</returns>
        /// <param name="haloColor">Halo color.</param>
        /// <param name="haloRadius">Halo radius.</param>
        public override uint AddTextLine(int layer, float minZoom, float maxZoom, double[] x, double[] y, int color,
                                         double font_size, string text, int?haloColor, int?haloRadius)
        {         // add the textline but simplify it for higher zoom levels.
            float currentMaxZoom = float.MaxValue;

            for (int idx = 0; idx < _zoomLevelCutoffs.Count; idx++)
            {
                float currentMinZoom = _zoomLevelCutoffs [idx];
                if (!(currentMinZoom > maxZoom) && !(currentMaxZoom < minZoom))
                {
                    float thisMinZoom = System.Math.Max(currentMinZoom, minZoom);
                    float thisMaxZoom = System.Math.Min(currentMaxZoom, maxZoom);

                    // simplify the algorithm.
                    double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y },
                                                                                            this.CalculateSimplificationEpsilon(thisMaxZoom));
                    if (this.CalculateSimplificationSurfaceCondition(currentMaxZoom, x, y))
                    {
                        // add to the scene.
                        if (_scenes [idx] == null)
                        {
                            _scenes [idx] = new Scene2DSimple();
                        }
                        _scenes [idx].AddTextLine(layer, thisMinZoom, thisMaxZoom, simplified [0], simplified [1], color, font_size, text,
                                                  haloColor, haloRadius);
                    }
                }
                currentMaxZoom = currentMinZoom;                 // move to the next cutoff.
            }
            return(0);
        }
Exemple #3
0
        /// <summary>
        /// Adds a line.
        /// </summary>
        /// <param name="maxZoom"></param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="width">Width.</param>
        /// <param name="minZoom"></param>
        /// <returns>The line.</returns>
        public override uint AddLine(int layer, float minZoom, float maxZoom, double[] x, double[] y,
                                     int color, double width, LineJoin lineJoin, int[] dashes)
        {         // add the line but simplify it for higher zoom levels.
            float currentMaxZoom = float.MaxValue;

            for (int idx = 0; idx < _zoomLevelCutoffs.Count; idx++)
            {
                float currentMinZoom = _zoomLevelCutoffs[idx];
                if (!(currentMinZoom >= maxZoom) && !(currentMaxZoom < minZoom))
                {
                    float thisMinZoom = System.Math.Max(currentMinZoom, minZoom);
                    float thisMaxZoom = System.Math.Min(currentMaxZoom, maxZoom);

                    // simplify the algorithm.
                    double     epsilon    = this.CalculateSimplificationEpsilon(thisMaxZoom);
                    double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y },
                                                                                            epsilon);
                    double distance = epsilon;
                    if (simplified[0].Length == 2)
                    { // check if the simplified version is smaller than epsilon.
                        OsmSharp.Math.Primitives.PointF2D point1 = new OsmSharp.Math.Primitives.PointF2D(
                            simplified[0][0], simplified[0][1]);
                        OsmSharp.Math.Primitives.PointF2D point2 = new OsmSharp.Math.Primitives.PointF2D(
                            simplified[1][0], simplified[0][1]);
                        distance = point1.Distance(point2);
                    }
                    if (distance >= epsilon &&
                        this.CalculateSimplificationSurfaceCondition(currentMaxZoom, x, y))
                    {
                        // add to the scene.
                        if (_scenes[idx] == null)
                        {
                            _scenes[idx] = new Scene2DSimple();
                        }
                        _scenes[idx].AddLine(layer, thisMinZoom, thisMaxZoom, simplified[0], simplified[1],
                                             color, width, lineJoin, dashes);
                    }
                }
                currentMaxZoom = currentMinZoom; // move to the next cutoff.
            }
            return(0);
        }
        /// <summary>
        /// Adds the polygon.
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="maxZoom"></param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="width">Width.</param>
        /// <returns>The polygon.</returns>
        /// <param name="minZoom">Minimum zoom.</param>
        /// <param name="fill">If set to <c>true</c> fill.</param>
        public override uint AddPolygon(int layer, float minZoom, float maxZoom, double[] x, double[] y, int color, double width, 
		                                 bool fill)
        {
            // add the polygon but simplify it for higher zoom levels.
            float currentMaxZoom = float.MaxValue;
            for (int idx = 0; idx < _zoomLevelCutoffs.Count; idx++) {
                float currentMinZoom = _zoomLevelCutoffs [idx];
                if (!(currentMinZoom >= maxZoom) && !(currentMaxZoom < minZoom)) {
                    float thisMinZoom = System.Math.Max (currentMinZoom, minZoom);
                    float thisMaxZoom = System.Math.Min (currentMaxZoom, maxZoom);

                    // simplify the algorithm.
                    double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify (new double[][] { x, y },
                    this.CalculateSimplificationEpsilon(thisMaxZoom));

                    if (simplified[0].Length > 2 &&
                        this.CalculateSimplificationSurfaceCondition(currentMaxZoom, x, y))
                    {
                        // add to the scene.
                        if (_scenes[idx] == null)
                        {
                            _scenes[idx] = new Scene2DSimple();
                        }
                        _scenes[idx].AddPolygon(thisMinZoom, thisMaxZoom, simplified[0], simplified[1], color, width, fill);
                    }
                }
                currentMaxZoom = currentMinZoom; // move to the next cutoff.
            }
            return 0;
        }
        /// <summary>
        /// Adds a line.
        /// </summary>
        /// <param name="maxZoom"></param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="width">Width.</param>
        /// <param name="minZoom"></param>
        /// <returns>The line.</returns>
        public override uint AddLine(int layer, float minZoom, float maxZoom, double[] x, double[] y,
            int color, double width, LineJoin lineJoin, int[] dashes)
        {
            // add the line but simplify it for higher zoom levels.
            float currentMaxZoom = float.MaxValue;
            for (int idx = 0; idx < _zoomLevelCutoffs.Count; idx++)
            {
                float currentMinZoom = _zoomLevelCutoffs[idx];
                if (!(currentMinZoom >= maxZoom) && !(currentMaxZoom < minZoom))
                {
                    float thisMinZoom = System.Math.Max(currentMinZoom, minZoom);
                    float thisMaxZoom = System.Math.Min(currentMaxZoom, maxZoom);

                    // simplify the algorithm.
                    double epsilon = this.CalculateSimplificationEpsilon(thisMaxZoom);
                    double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y },
                                                                    epsilon);
                    double distance = epsilon * 2;
                    if (simplified[0].Length == 2)
                    { // check if the simplified version is smaller than epsilon.
                        OsmSharp.Math.Primitives.PointF2D point1 = new OsmSharp.Math.Primitives.PointF2D(
                            simplified[0][0], simplified[0][1]);
                        OsmSharp.Math.Primitives.PointF2D point2 = new OsmSharp.Math.Primitives.PointF2D(
                            simplified[1][0], simplified[0][1]);
                        distance = point1.Distance(point2);
                    }
                    if (distance >= epsilon)
                    {
                        // add to the scene.
                        if (_scenes[idx] == null)
                        {
                            _scenes[idx] = new Scene2DSimple();
                        }
                        _scenes[idx].AddLine(layer, thisMinZoom, thisMaxZoom, simplified[0], simplified[1],
                            color, width, lineJoin, dashes);
                    }
                }
                currentMaxZoom = currentMinZoom; // move to the next cutoff.
            }
            return 0;
        }
Exemple #6
0
 /// <summary>
 /// Creates a new scene layer.
 /// </summary>
 /// <param name="index"></param>
 public LayerScene(IScene2DPrimitivesSource index)
 {
     _index = index;
     _scene2DSimple = new Scene2DSimple();
 }
Exemple #7
0
        /// <summary>
        /// Builds the scene.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="zoomFactor"></param>
        /// <param name="center"></param>
        /// <param name="view"></param>
        private void BuildScene(Map map, float zoomFactor, GeoCoordinate center, View2D view)
        {
            // build the boundingbox.
            var viewBox = view.OuterBox;
            var box = new GeoCoordinateBox (map.Projection.ToGeoCoordinates (viewBox.Min [0], viewBox.Min [1]),
                                            map.Projection.ToGeoCoordinates (viewBox.Max [0], viewBox.Max [1]));
            var zoomLevel = (int)map.Projection.ToZoomLevel (zoomFactor);
            if (_lastBox != null && _lastBox.Contains (box) &&
                zoomLevel == _lastZoom) {
                return;
            }
            _lastBox = box;
            _lastZoom = zoomLevel;

            // reset the scene.
            _scene2DSimple = new Scene2DSimple();

            // get from the index.
            this.Scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value;
            lock (_sync) {
                _index.Get (_scene2DSimple, view, zoomFactor);
            }
        }
        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);
        }
        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--;
                }
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.sampleControl1.Center = new double[] { 534463.21f, 6633094.69f };
            //this.sampleControl1.Center = new float[] { 0f, 0f };
            this.sampleControl1.ZoomFactor = 1;

            // initialize a test-scene.
            var scene2D = new Scene2DSimple();
            scene2D.BackColor = Color.White.ToArgb();
            scene2D.AddPoint(float.MinValue, float.MaxValue, 0, 0, Color.Blue.ToArgb(), 1);

            bool fill = false;
            int color = Color.White.ToArgb();
            int width = 1;

            scene2D.AddPolygon(float.MinValue, float.MaxValue,
                new double[] { 50, -80, 70 }, new double[] { 20, -10, -70 }, color, width, fill);

            // load test osm file.
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "OsmSharp.WinForms.UI.Sample.test.osm");
            var xmlDataProcessorSource = new XmlOsmStreamSource(stream);
            ICollection<OsmGeo> osmList = new List<OsmGeo>(xmlDataProcessorSource);

            // build a scene using spherical mercator.
            IProjection sphericalMercator = new WebMercator();
            var nodes = new Dictionary<long, GeoCoordinate>();
            foreach (OsmGeo simpleOsmGeo in osmList)
            {
                if (simpleOsmGeo is Node)
                {
                    var simplenode = (simpleOsmGeo as Node);
                    double[] point = sphericalMercator.ToPixel(
                        simplenode.Latitude.Value, simplenode.Longitude.Value);
                    nodes.Add(simplenode.Id.Value,
                        new GeoCoordinate(simplenode.Latitude.Value, simplenode.Longitude.Value));
                    scene2D.AddPoint(float.MinValue, float.MaxValue, (float)point[0], (float)point[1],
                                     Color.Yellow.ToArgb(),
                                     2);
                }
                else if (simpleOsmGeo is Way)
                {
                    var way = (simpleOsmGeo as Way);
                    var x = new List<double>();
                    var y = new List<double>();
                    if (way.Nodes != null)
                    {
                        for (int idx = 0; idx < way.Nodes.Count; idx++)
                        {
                            GeoCoordinate nodeCoords;
                            if (nodes.TryGetValue(way.Nodes[idx], out nodeCoords))
                            {
                                x.Add((float) sphericalMercator.LongitudeToX(nodeCoords.Longitude));
                                y.Add((float) sphericalMercator.LatitudeToY(nodeCoords.Latitude));
                            }
                        }
                    }

                    if (x.Count > 0)
                    {
                        scene2D.AddLine(float.MinValue, float.MaxValue, x.ToArray(), y.ToArray(),
                            Color.Blue.ToArgb(), 2);
                    }
                }
            }

            this.sampleControl1.Scene = scene2D;

            this.sampleControl1.Invalidate();
        }
        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();
            Scene2DSimple scene = new Scene2DSimple();

            // 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.
            List<IScene2DPrimitive> primitives = scene.Get(0);
            Assert.IsNotNull(primitives);
            Assert.AreEqual(1, primitives.Count);
            IScene2DPrimitive primitive = primitives[0];
            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf<Point2D>(primitive);
            Point2D point = primitive as Point2D;
            Assert.AreEqual(2, point.Size);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, point.Color);
            Assert.AreEqual(mercator.LongitudeToX(1), point.X);
            Assert.AreEqual(mercator.LatitudeToY(1), point.Y);

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

            // test the scene line 2.
            primitives = scene.Get(2);
            Assert.IsNotNull(primitives);
            Assert.AreEqual(1, primitives.Count);
            primitive = primitives[0];
            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]);
        }
        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 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);
        }
Exemple #14
0
        /// <summary>
        /// Adds a text along a line to this scene.
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="minZoom"></param>
        /// <param name="maxZoom"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="color"></param>
        /// <param name="font_size"></param>
        /// <param name="text"></param>
        /// <returns>The text line.</returns>
        /// <param name="haloColor">Halo color.</param>
        /// <param name="haloRadius">Halo radius.</param>
        public override uint AddTextLine(int layer, float minZoom, float maxZoom, double[] x, double[] y, int color, 
		                                  double font_size, string text, int? haloColor, int? haloRadius)
        {
            // add the textline but simplify it for higher zoom levels.
            float currentMaxZoom = float.MaxValue;
            for (int idx = 0; idx < _zoomLevelCutoffs.Count; idx++) {
                float currentMinZoom = _zoomLevelCutoffs [idx];
                if (!(currentMinZoom > maxZoom) && !(currentMaxZoom < minZoom))
                {
                    float thisMinZoom = System.Math.Max(currentMinZoom, minZoom);
                    float thisMaxZoom = System.Math.Min(currentMaxZoom, maxZoom);

                    // simplify the algorithm.
                    double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y },
                        this.CalculateSimplificationEpsilon(thisMaxZoom));
                    //if (this.CalculateSimplificationSurfaceCondition (currentMaxZoom, x, y)) {
                    // add to the scene.
                    if (_scenes[idx] == null)
                    {
                        _scenes[idx] = new Scene2DSimple();
                    }
                    _scenes[idx].AddTextLine(layer, thisMinZoom, thisMaxZoom, simplified[0], simplified[1], color, font_size, text,
                                              haloColor, haloRadius);
                    //}
                }
                currentMaxZoom = currentMinZoom; // move to the next cutoff.
            }
            return 0;
        }
Exemple #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OsmSharp.UI.Renderer.Scene.Scene2DLayered"/> class.
 /// </summary>
 /// <param name="zoomLevelCutoffs">Zoom level cutoffs.</param>
 public Scene2DLayered(List <float> zoomLevelCutoffs)
 {
     _zoomLevelCutoffs   = zoomLevelCutoffs;
     _scenes             = new Scene2DSimple[_zoomLevelCutoffs.Count];
     _nonSimplifiedScene = new Scene2DSimple();
 }
Exemple #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OsmSharp.UI.Renderer.Scene.Scene2DLayered"/> class.
 /// </summary>
 /// <param name="zoomLevelCutoffs">Zoom level cutoffs.</param>
 public Scene2DLayered(List<float> zoomLevelCutoffs)
 {
     _zoomLevelCutoffs = zoomLevelCutoffs;
     _scenes = new Scene2DSimple[_zoomLevelCutoffs.Count];
     _nonSimplifiedScene = new Scene2DSimple ();
 }
Exemple #17
0
        /// <summary>
        /// Called when the mapview has changed.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="zoomFactor"></param>
        /// <param name="center"></param>
        /// <param name="view"></param>
        public void ViewChanged(OsmSharp.UI.Map.Map map, float zoomFactor, GeoCoordinate center,
            View2D view)
        {
            // calculate the current zoom level.
            var zoomLevel = (int)System.Math.Round(map.Projection.ToZoomLevel(zoomFactor), 0);

            // build the boundingbox.
            var viewBox = view.OuterBox;
            var box = new GeoCoordinateBox (map.Projection.ToGeoCoordinates (viewBox.Min [0], viewBox.Min [1]),
                                            map.Projection.ToGeoCoordinates (viewBox.Max [0], viewBox.Max [1]));

            // build the tile range.
            TileRange range = TileRange.CreateAroundBoundingBox(box, zoomLevel);
            DateTime now = DateTime.Now;

            // build the new scene.
            Scene2D newScene = new Scene2DSimple();
            if (_connection.State == System.Data.ConnectionState.Closed)
            {
                _connection.Open();
            }
            lock (_connection)
            { // make sure the connection is accessed synchronously.
                // TODO: Investigate the SQLite multithreaded behaviour..
                // TODO: this a very naive way of loading these tiles. Find a way to query SQLite more efficiently
                // TODO: find a way to have some cached tiles.
                foreach (var tile in range)
                {
                    Tile invertTile = tile.InvertY();

                    SQLiteCommand command = new SQLiteCommand("SELECT * FROM tiles WHERE zoom_level = :zoom_level AND tile_column = :tile_column AND tile_row = :tile_row;",
                        _connection);
                    command.Parameters.AddWithValue("zoom_level", invertTile.Zoom);
                    command.Parameters.AddWithValue("tile_column", invertTile.X);
                    command.Parameters.AddWithValue("tile_row", invertTile.Y);
                    using (var tileReader = command.ExecuteReader())
                    {
                        while (tileReader.Read())
                        {
                            //Tile readTile = new Tile((int)tileReader["tile_column"],
                            //    (int)tileReader["tile_row"], (int)tileReader["zoom_level"]);

                            float minZoom = (float)map.Projection.ToZoomFactor(tile.Zoom - 0.5f);
                            float maxZoom = (float)map.Projection.ToZoomFactor(tile.Zoom + 0.5f);
                            float left = (float)map.Projection.LongitudeToX(tile.TopLeft.Longitude);
                            float right = (float)map.Projection.LongitudeToX(tile.BottomRight.Longitude);
                            float bottom = (float)map.Projection.LatitudeToY(tile.BottomRight.Latitude);
                            float top = (float)map.Projection.LatitudeToY(tile.TopLeft.Latitude);

                            newScene.AddImage(0, minZoom, maxZoom, left, top, right, bottom,
                                                (byte[])tileReader["tile_data"]);
                        }
                    }
                }
                this.Scene = newScene;
            }
        }