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 Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);
            var projection = new WebMercator();
            GeoCoordinateBox box = null;
            foreach (var osmGeo in dataSource)
            {
                ICompleteOsmGeo completeOsmGeo = null;
                switch (osmGeo.Type)
                {
                    case OsmGeoType.Node:
                        completeOsmGeo = osmGeo as Node;
                        if(completeOsmGeo.Tags == null)
                        { // make sure every node has a tags collection.
                            completeOsmGeo.Tags = new TagsCollection();
                        }
                        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.
            TagsCollectionBase metaTags = new TagsCollection();
            metaTags.Add("SomeTestKey", "SomeTestValue");
            var stream = new MemoryStream();
            scene.Serialize(stream, true, metaTags);

            // deserialize the stream.
            metaTags = null;
            stream.Seek(0, SeekOrigin.Begin);
            IPrimitives2DSource sceneSource = Scene2D.Deserialize(stream, true, out metaTags);

            // test meta tags.
            Assert.IsTrue(metaTags.ContainsKeyValue("SomeTestKey", "SomeTestValue"));

            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 Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);
                    IEnumerable<Primitive2D> primitives = sceneSource.Get(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--;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Raises the create event.
        /// </summary>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            OsmSharp.Logging.Log.Enable();

            //			OsmSharp.IO.Output.OutputStreamHost.RegisterOutputStream (
            //				new OsmSharp.Android.UI.IO.Output.ConsoleOutputStream ());

            // create the MapCSS image source.
            var imageSource = new MapCSSDictionaryImageSource();
            imageSource.Add("styles/default/parking.png",
                            Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.parking.png"));
            imageSource.Add("styles/default/bus.png",
                            Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.bus.png"));
            imageSource.Add("styles/default/postbox.png",
                            Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.postbox.png"));

            //			// load mapcss style interpreter.
            //			var mapCSSInterpreter = new MapCSSInterpreter(
            //				Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.mapcss"),
            //				imageSource);

            // initialize the data source.
            //var dataSource = new MemoryDataSource();
            //			var source = new XmlOsmStreamReader(
            //				Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm"));
            //			var source = new PBFOsmStreamReader(
            //				Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm.pbf"));
            //			dataSource.PullFromSource(source);

            // initialize map.
            var map = new Map();
            //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter));
            //			map.AddLayer(new LayerScene(Scene2DSimple.Deserialize(
            //							Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.osm.pbf.scene.simple"), true)));
            map.AddLayer(
                new LayerScene(
                Scene2DLayered.Deserialize(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.wvl.map"), true)));

            //			var routingSerializer = new V2RoutingDataSourceLiveEdgeSerializer(true);
            //			var graphSerialized = routingSerializer.Deserialize(
            //				//Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm.pbf.routing.3"));
            //				Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.pbf.routing.4"));
            ////
            ////			var graphLayer = new LayerDynamicGraphLiveEdge(graphSerialized, mapCSSInterpreter);
            ////			map.AddLayer(graphLayer);
            //
            //			// calculate route.
            //			Router router = Router.CreateLiveFrom(
            //				graphSerialized,
            //				new OsmRoutingInterpreter());

            var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false);
            var graphDeserialized = routingSerializer.Deserialize(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.routing"), true);

            _router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());
            GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545);
            GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793);
            RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, point1);
            RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, point2);
            Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
            RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter());
            _enumerator = route1.GetRouteEnumerable(20).GetEnumerator();

            _routeLayer = new LayerRoute(map.Projection);
            _routeLayer.AddRoute (route1, SimpleColor.FromKnownColor(KnownColor.Blue).Value);
            map.AddLayer(_routeLayer);

            //			// create gpx layer.
            //			LayerGpx gpxLayer = new LayerGpx(map.Projection);
            //			gpxLayer.AddGpx(
            //				Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.gpx"));
            //			map.AddLayer(gpxLayer);

            //			// set control properties.
            //			var mapView = new MapView(this);
            //			mapView.MapMaxZoomLevel = 20;
            //			mapView.MapMinZoomLevel = 12;
            //			//var mapView = new MapGLView (this);
            //			mapView.Map = map;
            //			//mapView.Center = new GeoCoordinate(51.158075, 2.961545); // gistel
            //			//mapView.MapCenter = new GeoCoordinate (50.88672, 3.23899);
            //			mapView.MapCenter = new GeoCoordinate(51.26337, 4.78739);
            //			//mapView.Center = new GeoCoordinate(51.156803, 2.958887);
            //			mapView.MapZoomLevel = 15;

            //			var mapView = new OpenGLRenderer2D(
            //				this, null);

            //            _mapView = new MapView<MapGLView>(this, new MapGLView(this));

            _mapView = new MapView(this, new MapViewSurface(this));
            //_mapView = new MapView(this, new MapViewGLSurface(this));
            _mapView.Map = map;

            (_mapView as IMapView).AutoInvalidate = true;
            _mapView.MapMaxZoomLevel = 20;
            _mapView.MapMinZoomLevel = 12;
            _mapView.MapTilt = 0;
            //var mapView = new MapGLView (this);
            _mapView.MapCenter = new GeoCoordinate(51.158075, 2.961545); // gistel
            //mapView.MapCenter = new GeoCoordinate (50.88672, 3.23899);
            //mapLayout.MapCenter = new GeoCoordinate(51.26337, 4.78739);
            //mapView.Center = new GeoCoordinate(51.156803, 2.958887);
            _mapView.MapZoom = 17;
            //MapViewAnimator mapViewAnimator = new MapViewAnimator(mapLayout);
            //_mapView.MapTapEvent += delegate(GeoCoordinate geoCoordinate)
            //{
            //    _mapView.ZoomToMarkers();
            //    //_mapView.AddMarker(geoCoordinate).Click += new EventHandler(MainActivity_Click);
            //    //mapViewAnimator.Stop();
            //    //mapViewAnimator.Start(geoCoordinate, 15, new TimeSpan(0, 0, 2));
            //};

            //Create the user interface in code
            var layout = new RelativeLayout (this);
            layout.AddView(_mapView);

            _mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795));
            _mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483));

            //_mapView.ZoomToMarkers();

            _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5);

            Timer timer = new Timer(250);
            timer.Elapsed += new ElapsedEventHandler(TimerHandler);
            timer.Start();

            SetContentView (layout);
        }
Пример #3
0
        /// <summary>
        /// Raises the OnLoad event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // create the MapCSS image source.
            var imageSource = new MapCSSDictionaryImageSource();
            imageSource.Add("styles/default/parking.png",
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.images.parking.png"));
            imageSource.Add("styles/default/bus.png",
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.images.bus.png"));
            imageSource.Add("styles/default/postbox.png",
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.images.postbox.png"));

            // load mapcss style interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                new FileInfo(@"C:\Users\xivk\Dropbox\SharpSoftware\Projects\Westtour WOI\wvl.mapcss").OpenRead(),
                imageSource);

            // initialize the data source.
            //var dataSource = MemoryDataSource.CreateFromXmlStream(new FileInfo(@"c:\OSM\bin\wechel.osm").OpenRead());
            var dataSource = MemoryDataSource.CreateFromPBFStream(new FileInfo(@"C:\OSM\bin\wvl.osm.pbf").OpenRead());
            //var dataSource = MemoryDataSource.CreateFromPBFStream(new FileInfo(@"c:\OSM\bin\gent.osm.pbf").OpenRead());
            //var dataSource = MemoryDataSource.CreateFromPBFStream(new FileInfo(@"c:\OSM\bin\lebbeke.osm.pbf").OpenRead());
            //Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.test.osm"));

            // initialize map.
            var map = new OsmSharp.UI.Map.Map();
            map.AddLayer(new LayerOsm(dataSource, mapCSSInterpreter, map.Projection));
            //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            //map.AddLayer(new LayerMBTile(@"C:\Users\xivk\Documents\Nostalgeo.mbtiles"));
            //map.AddLayer(
            //    new LayerScene(
            //        Scene2DLayered.Deserialize(new FileInfo(@"c:\OSM\bin\kempen.osm.pbf.scene.layered").OpenRead(), true)));
            //map.AddLayer(
            //    new LayerScene(
            //        Scene2DLayered.Deserialize(new FileInfo(@"c:\OSM\bin\wvl.map").OpenRead(), true)));

            //this.InitializeRouting(map);

            //// create gpx layer.
            //var gpxLayer = new LayerGpx(map.Projection);
            //gpxLayer.AddGpx(
            //    Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.test.gpx"));
            //map.AddLayer(gpxLayer);

            // set control properties.
            this.mapControl1.Map = map;
            //this.mapControl1.Center = new GeoCoordinate(51.26371, 4.7854); //51.26371&lon=4.7854 // wechel.osm
            //this.mapControl1.Center = new GeoCoordinate(50.88672, 3.23899); // lendelede
            //this.mapControl1.Center = new GeoCoordinate(50.9523195, 3.0997436);
            //this.mapControl1.MapCenter = new GeoCoordinate(51.22105, 2.93419); // oostende spoor.
            this.mapControl1.MapCenter = new GeoCoordinate(51.156803, 2.958887); // gistel
            //this.mapControl1.MapCenter = new GeoCoordinate(51.05608, 3.72139); // gent
            //this.mapControl1.Center = new GeoCoordinate(50.9969, 4.1201);
            this.mapControl1.MapZoom = 19;
        }