示例#1
0
        /// <summary>
        /// Initialize this instance.
        /// </summary>
        void Initialize(MapView mapLayout)
        {
            _mapLayout = mapLayout;
            this.SetWillNotDraw(false);

            this.MapMinZoomLevel = 10;
            this.MapMaxZoomLevel = 20;

            _renderer = new MapRenderer <global::Android.Graphics.Canvas>(
                new CanvasRenderer2D());

            // initialize the gesture detection.
            _gestureDetector = new GestureDetector(
                this);
            _scaleGestureDetector = new ScaleGestureDetector(
                this.Context, this);
            this.SetOnTouchListener(this);

            _makerLayer = new LayerPrimitives(
                new WebMercator());

            // initialize all the caching stuff.
            //_previousCache = null;
            _cacheRenderer = new MapRenderer <global::Android.Graphics.Canvas>(
                new CanvasRenderer2D());
            _scene           = new Scene2DSimple();
            _scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value;

            System.Threading.Timer timer = new Timer(InvalidateSimple,
                                                     null, 0, 50);
        }
示例#2
0
        /// <summary>
        /// Initialize implementation from IMapView.
        /// </summary>
        /// <param name="mapLayout"></param>
        void IMapViewSurface.Initialize(MapView mapLayout)
        {
            // create the Open GL 2D target.
            _target = new OpenGLTarget2D();
            this.SetRenderer(_target);

            _mapView = mapLayout;
            this.SetWillNotDraw(false);

            this.MapMinZoomLevel = 10;
            this.MapMaxZoomLevel = 20;

            // create the renderer.
            _renderer = new MapRenderer <OpenGLTarget2D>(
                new OpenGLRenderer2D());

            // initialize the gesture detection.
            this.SetOnTouchListener(this);
            _scaleGestureDetector = new ScaleGestureDetector(
                this.Context, this);
            _rotateGestureDetector = new RotateGestureDetector(
                this.Context, this);
            _moveGestureDetector = new MoveGestureDetector(
                this.Context, this);
            _tagGestureDetector = new TapGestureDetector(
                this.Context, this);

            _makerLayer = new LayerPrimitives(
                new WebMercator());

            _scene           = new Scene2DSimple();
            _scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value;
        }
示例#3
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.
            if (_scene2DSimple == null)
            {
                _scene2DSimple = new Scene2DSimple();
            }
            _scene2DSimple.Clear();

            // get from the index.
            this.Scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value;
            lock (_sync) {
                _index.Get(_scene2DSimple, view, zoomFactor);
            }
        }
示例#4
0
        /// <summary>
        /// Fills the given simple scene with objects inside the given view and for the given zoomFactor.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        public void Get(Scene2DSimple scene, View2D view, float zoomFactor)
        {
            lock (_stream) {             // make sure there is only synchonous access to the stream.
                // check what is in the non-simplified scene.
                IScene2DPrimitivesSource simpleSource = this.GetNonSimplifiedStream();
                simpleSource.Get(scene, view, zoomFactor);

                // check what index this zoomfactor is for.
                int idx = this.SearchForScene(zoomFactor);
                if (idx >= 0)                                              // the index was found.
                {
                    if (!_loadedScenes.TryGetValue(idx, out simpleSource)) // the scene was not found.
                    {
                        long position = _index.SceneIndexes [idx];
                        _stream.Seek(position, SeekOrigin.Begin);
                        LimitedStream stream = new LimitedStream(_stream);
                        //Scene2DRTreeSerializer serializer = new Scene2DRTreeSerializer(true);
                        //simpleSource = new Scene2DPrimitivesSource(serializer.Deserialize(stream));
                        OsmSharp.UI.Renderer.Scene.Storage.Styled.Scene2DStyledSerializer serializer =
                            new Styled.Scene2DStyledSerializer();
                        simpleSource = serializer.Deserialize(stream, true);
                        _loadedScenes.Add(idx, simpleSource);
                    }
                    simpleSource.Get(scene, view, zoomFactor);

                    OsmSharp.Logging.Log.TraceEvent("Scene2DLayeredSource", System.Diagnostics.TraceEventType.Verbose,
                                                    string.Format("Deserialized from scene at zoom {0} and idx {1} synchronized.", zoomFactor, idx));
                }
            }
        }
示例#5
0
        /// <summary>
        /// Initialize this instance.
        /// </summary>
        public void Initialize()
        {
            this.BackgroundColor = UIColor.White;

            var panGesture = new UIPanGestureRecognizer(Pan);

            this.AddGestureRecognizer(panGesture);
            var pinchGesture = new UIPinchGestureRecognizer(Pinch);

            this.AddGestureRecognizer(pinchGesture);

//			// create the renderer
//			_renderer = new MapRenderer<CGContextWrapper> (
//				new CGContextRenderer());
//
            // create the cache renderer.
            _cacheRenderer = new MapRenderer <CGContextWrapper> (
                new CGContextRenderer());
            _cachedScene           = new Scene2DSimple();
            _cachedScene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value;

            // create invalidation timer.
            _render = true;
            System.Threading.Timer timer = new System.Threading.Timer(InvalidateSimple,
                                                                      null, 0, 50);
        }
示例#6
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);
        }
示例#7
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;
            }
        }
示例#8
0
        /// <summary>
        /// Adds all primitives inside the given box for the given zoom.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        public void Get(Scene2DSimple scene, View2D view, float zoomFactor)
        {
            // get all primitives.
            IEnumerable <Scene2DEntry> entries =
                _index.Get(view.OuterBox);

            foreach (var scene2DEntry in entries)
            {
                scene.AddPrimitive(scene2DEntry.Layer, scene2DEntry.Id, scene2DEntry.Scene2DPrimitive);
            }
        }
        /// <summary>
        /// Adds all primitives inside the given box for the given zoom.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        public void Get(Scene2DSimple scene, View2D view, float zoomFactor)
        {
            // get all primitives.
            IEnumerable<Scene2DEntry> entries =
                _index.Get(view.OuterBox);

            foreach (var scene2DEntry in entries)
            {
                scene.AddPrimitive(scene2DEntry.Layer, scene2DEntry.Id, scene2DEntry.Scene2DPrimitive);
            }
        }
示例#10
0
        public void Initialize()
        {
            // initialize a test-map.
            var map = new Map();

            map.AddLayer(new LayerScene(Scene2DSimple.Deserialize(
                                            Assembly.GetExecutingAssembly().GetManifestResourceStream(
                                                "OsmSharp.WindowsPhone.UI.Sample.wvl.osm.pbf.scene.simple"), true)));

            // initializes this map.
            this.Map       = map;
            this.Center    = new OsmSharp.Math.Geo.GeoCoordinate(51.158075, 2.961545);
            this.ZoomLevel = 16;
        }
示例#11
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 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(0, scene.Count);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Green).Value, scene.BackColor);
        }
        /// <summary>
        /// Serializes the given scene to the given stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="scenes"></param>
        /// <param name="zoomCutoffs"></param>
        /// <param name="compress"></param>
        public void Serialize(Stream stream, Scene2DSimple nonSimplifiedScene,
                              Scene2DSimple[] scenes, List <float> zoomCutoffs, bool compress)
        {
            // first move to store the position of the index.
            stream.Write(new byte[4], 0, 4);

            // serialize all the scenes.
            List <long>  sceneIndexes = new List <long>();
            MemoryStream sceneStream;

            for (int idx = 0; idx < scenes.Length; idx++)
            {
                if (scenes[idx] != null)
                {
                    sceneStream = new MemoryStream();
                    scenes[idx].SerializeStyled(sceneStream, compress);

                    sceneIndexes.Add(stream.Position);
                    sceneStream.WriteTo(stream);
                    sceneStream.Dispose();
                }
            }
            sceneIndexes.Add(stream.Position);

            // serialize the non-simplified scene.
            sceneStream = new MemoryStream();
            nonSimplifiedScene.SerializeStyled(sceneStream, compress);
            sceneStream.WriteTo(stream);
            sceneStream.Dispose();

            // serialize the index.
            Scene2DLayeredIndex sceneIndex = new Scene2DLayeredIndex();

            sceneIndex.SceneCutoffs = zoomCutoffs.ToArray();
            sceneIndex.SceneIndexes = sceneIndexes.ToArray();
            int sceneIndexIndex = (int)stream.Position;

            RuntimeTypeModel typeModel = TypeModel.Create();

            typeModel.Add(typeof(Scene2DLayeredIndex), true); // the tile metadata.
            typeModel.Serialize(stream, sceneIndex);

            // write the position.
            stream.Seek(0, SeekOrigin.Begin);
            stream.Write(BitConverter.GetBytes(sceneIndexIndex), 0, 4);
            stream.Flush();
        }
        /// <summary>
        /// Serializes the given scene to the given stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="scenes"></param>
        /// <param name="zoomCutoffs"></param>
        /// <param name="compress"></param>
        public void Serialize(Stream stream, Scene2DSimple nonSimplifiedScene,
            Scene2DSimple[] scenes, List<float> zoomCutoffs, bool compress)
        {
            // first move to store the position of the index.
            stream.Write(new byte[4], 0, 4);

            // serialize all the scenes.
            List<long> sceneIndexes = new List<long>();
            MemoryStream sceneStream;
            for(int idx = 0; idx < scenes.Length; idx++)
            {
                if(scenes[idx] != null)
                {
                    sceneStream = new MemoryStream();
                    scenes[idx].SerializeStyled(sceneStream, compress);

                    sceneIndexes.Add(stream.Position);
                    sceneStream.WriteTo(stream);
                    sceneStream.Dispose();
                }
            }
            sceneIndexes.Add(stream.Position);

            // serialize the non-simplified scene.
            sceneStream = new MemoryStream();
            nonSimplifiedScene.SerializeStyled(sceneStream, compress);
            sceneStream.WriteTo(stream);
            sceneStream.Dispose();

            // serialize the index.
            Scene2DLayeredIndex sceneIndex = new Scene2DLayeredIndex();
            sceneIndex.SceneCutoffs = zoomCutoffs.ToArray();
            sceneIndex.SceneIndexes = sceneIndexes.ToArray();
            int sceneIndexIndex = (int)stream.Position;

            RuntimeTypeModel typeModel = TypeModel.Create();
            typeModel.Add(typeof(Scene2DLayeredIndex), true); // the tile metadata.
            typeModel.Serialize(stream, sceneIndex);

            // write the position.
            stream.Seek(0, SeekOrigin.Begin);
            stream.Write(BitConverter.GetBytes(sceneIndexIndex), 0, 4);
            stream.Flush();
        }
示例#14
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);
        }
示例#15
0
        /// <summary>
        /// Builds the cached scene.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="currentCache"></param>
        /// <param name="currentScenes"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        protected override Scene2D BuildSceneCache(Target2DWrapper <Graphics> target, Scene2D currentCache,
                                                   List <Scene2D> currentScenes, View2D view)
        {
            var scene = new Scene2DSimple();

//            scene.BackColor = currentScenes[0].BackColor;
//
//	        var bitmap = target.Tag as Bitmap;
//	        if (bitmap != null)
//	        {
//
//				// 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]));
//
//	            scene.AddImage(0, float.MinValue, float.MaxValue,
//                    view.Left, view.Top, view.Right, view.Bottom, new byte[0], bitmap);
//	        }
            return(scene);
        }
示例#16
0
        /// <summary>
        /// Builds the cached scene.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="currentCache"></param>
        /// <param name="currentScenes"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        protected override Scene2D BuildSceneCache(Target2DWrapper <global::Android.Graphics.Canvas> target, Scene2D currentCache,
                                                   List <Scene2D> currentScenes, View2D view)
        {
            var scene = new Scene2DSimple();

//			scene.BackColor = currentScenes[0].BackColor;
//
//			var bitmap = target.Tag as global::Android.Graphics.Bitmap;
//			if (bitmap != null)
//			{
//				byte[] imageData = null;
//				using (var stream = new MemoryStream())
//				{
//					bitmap.Compress(global::Android.Graphics.Bitmap.CompressFormat.Png, 0, stream);
//
//					imageData = stream.ToArray();
//				}
//				scene.AddImage(0, float.MinValue, float.MaxValue,
//				               view.Left, view.Top, view.Right, view.Bottom, imageData);
//			}
            return(scene);
        }
        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--;
                }
            }
        }
示例#18
0
        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 = xmlDataProcessorSource.PullToCollection();

            // 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();
        }
示例#19
0
        /// <summary>
        /// Fills the given simple scene with objects inside the given view and for the given zoomFactor.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        public void Get(Scene2DSimple scene, View2D view, float zoomFactor)
        {
            lock (_stream) { // make sure there is only synchonous access to the stream.
                // check what is in the non-simplified scene.
                IScene2DPrimitivesSource simpleSource = this.GetNonSimplifiedStream ();
                simpleSource.Get (scene, view, zoomFactor);

                // check what index this zoomfactor is for.
                int idx = this.SearchForScene (zoomFactor);
                if (idx >= 0) { // the index was found.
                    if (!_loadedScenes.TryGetValue (idx, out simpleSource)) { // the scene was not found.
                        long position = _index.SceneIndexes [idx];
                        _stream.Seek (position, SeekOrigin.Begin);
                        LimitedStream stream = new LimitedStream (_stream);
                        //Scene2DRTreeSerializer serializer = new Scene2DRTreeSerializer(true);
                        //simpleSource = new Scene2DPrimitivesSource(serializer.Deserialize(stream));
                        OsmSharp.UI.Renderer.Scene.Storage.Styled.Scene2DStyledSerializer serializer =
                            new Styled.Scene2DStyledSerializer ();
                        simpleSource = serializer.Deserialize (stream, true);
                        _loadedScenes.Add (idx, simpleSource);
                    }
                    simpleSource.Get (scene, view, zoomFactor);

                    OsmSharp.Logging.Log.TraceEvent ("Scene2DLayeredSource", System.Diagnostics.TraceEventType.Verbose,
                        string.Format ("Deserialized from scene at zoom {0} and idx {1} synchronized.", zoomFactor, idx));
                }
            }
        }
示例#20
0
        /// <summary>
        /// Initialize the specified defaultMapCenter, defaultMap, defaultMapTilt and defaultMapZoom.
        /// </summary>
        /// <param name="defaultMapCenter">Default map center.</param>
        /// <param name="defaultMap">Default map.</param>
        /// <param name="defaultMapTilt">Default map tilt.</param>
        /// <param name="defaultMapZoom">Default map zoom.</param>
        public void Initialize(GeoCoordinate defaultMapCenter, Map defaultMap, Degree defaultMapTilt, float defaultMapZoom)
        {
            // set clip to bounds to prevent objects from being rendered/show outside of the mapview.
            this.ClipsToBounds = true;

            _mapCenter = defaultMapCenter;
            _map       = defaultMap;
            _mapTilt   = defaultMapTilt;
            _mapZoom   = defaultMapZoom;

            _doubleTapAnimator = new MapViewAnimator(this);

            this.BackgroundColor        = UIColor.White;
            this.UserInteractionEnabled = true;

            _markers = new List <MapMarker> ();

            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                var panGesture = new UIPanGestureRecognizer(Pan);
                panGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => {
                    return(true);
                };
                // TODO: workaround for xamarin bug, remove later!
                panGesture.ShouldRequireFailureOf   = (a, b) => { return(false); };
                panGesture.ShouldBeRequiredToFailBy = (a, b) => { return(false); };
                this.AddGestureRecognizer(panGesture);

                var pinchGesture = new UIPinchGestureRecognizer(Pinch);
                pinchGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => {
                    return(true);
                };
                // TODO: workaround for xamarin bug, remove later!
                pinchGesture.ShouldRequireFailureOf   = (a, b) => { return(false); };
                pinchGesture.ShouldBeRequiredToFailBy = (a, b) => { return(false); };
                this.AddGestureRecognizer(pinchGesture);

                var rotationGesture = new UIRotationGestureRecognizer(Rotate);
                rotationGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => {
                    return(true);
                };
                // TODO: workaround for xamarin bug, remove later!
                rotationGesture.ShouldRequireFailureOf   = (a, b) => { return(false); };
                rotationGesture.ShouldBeRequiredToFailBy = (a, b) => { return(false); };
                this.AddGestureRecognizer(rotationGesture);

                var singleTapGesture = new UITapGestureRecognizer(SingleTap);
                singleTapGesture.NumberOfTapsRequired = 1;
                // TODO: workaround for xamarin bug, remove later!
//				singleTapGesture.ShouldRequireFailureOf = (a, b) => { return false; };
//				singleTapGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; };

                var doubleTapGesture = new UITapGestureRecognizer(DoubleTap);
                doubleTapGesture.NumberOfTapsRequired = 2;
                // TODO: workaround for xamarin bug, remove later!
//				doubleTapGesture.ShouldRequireFailureOf = (a, b) => { return false; };
//				doubleTapGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; };

                //singleTapGesture.RequireGestureRecognizerToFail (doubleTapGesture);
                this.AddGestureRecognizer(singleTapGesture);
                this.AddGestureRecognizer(doubleTapGesture);
            }
            else
            {
                var panGesture = new UIPanGestureRecognizer(Pan);
                panGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return(true); };
                this.AddGestureRecognizer(panGesture);

                var pinchGesture = new UIPinchGestureRecognizer(Pinch);
                pinchGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return(true); };
                this.AddGestureRecognizer(pinchGesture);

                var rotationGesture = new UIRotationGestureRecognizer(Rotate);
                rotationGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return(true); };
                this.AddGestureRecognizer(rotationGesture);

                var singleTapGesture = new UITapGestureRecognizer(SingleTap);
                singleTapGesture.NumberOfTapsRequired = 1;
                //singleTapGesture.ShouldRecognizeSimultaneously += ShouldRecognizeSimultaneouslySingle;
                //singleTapGesture.ShouldBeRequiredToFailBy += ShouldRecognizeSimultaneouslySingle;

                var doubleTapGesture = new UITapGestureRecognizer(DoubleTap);
                doubleTapGesture.NumberOfTapsRequired = 2;
                //doubleTapGesture.ShouldRecognizeSimultaneously += ShouldRecognizeSimultaneouslySingle;
                //doubleTapGesture.ShouldBeRequiredToFailBy += ShouldRecognizeSimultaneouslyDouble;

                singleTapGesture.RequireGestureRecognizerToFail(doubleTapGesture);
                this.AddGestureRecognizer(singleTapGesture);
                this.AddGestureRecognizer(doubleTapGesture);
            }

            // set scalefactor.
            _scaleFactor = this.ContentScaleFactor;

            // create the cache renderer.
            _cacheRenderer = new MapRenderer <CGContextWrapper> (
                new CGContextRenderer(_scaleFactor));
            _cachedScene           = new Scene2DSimple();
            _cachedScene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value;
        }
示例#21
0
 /// <summary>
 /// Creates a new scene layer.
 /// </summary>
 /// <param name="index"></param>
 public LayerScene(IScene2DPrimitivesSource index)
 {
     _index         = index;
     _scene2DSimple = new Scene2DSimple();
 }
示例#22
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();
            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]);
        }