/// <summary>
        /// Does the actual testing.
        /// </summary>
        /// <param name="embeddedString"></param>
        private void DoRoutingSerializationV2CHRoutingV2ComparisonTest(string embeddedString)
        {
            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                     Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)),
                                                                 interpreter, Vehicle.Car);

            // create serializer.
            var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.v2.CHEdgeDataDataSourceSerializer(true);

            // serialize/deserialize.
            TagsCollectionBase metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            byte[] byteArray;
            using (var stream = new MemoryStream())
            {
                try
                {
                    routingSerializer.Serialize(stream, original, metaData);
                    byteArray = stream.ToArray();
                }
                catch (Exception)
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    throw;
                }
            }

            IBasicRouterDataSource <CHEdgeData> deserializedVersion =
                routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData);

            Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));
            Assert.IsTrue(deserializedVersion.SupportsProfile(Vehicle.Car));
            Assert.IsFalse(deserializedVersion.SupportsProfile(Vehicle.Bicycle));

            // create reference router.
            original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                 Assembly.GetExecutingAssembly()
                                                                 .GetManifestResourceStream(embeddedString)),
                                                             interpreter,
                                                             Vehicle.Car);
            var    basicRouterOriginal = new CHRouter();
            Router referenceRouter     = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var    basicRouter = new CHRouter();
            Router router      = Router.CreateCHFrom(
                deserializedVersion, basicRouter, interpreter);

            this.TestCompareAll(original, referenceRouter, router);
        }
        /// <summary>
        /// Does the actual testing.
        /// </summary>
        /// <param name="embeddedString"></param>
        private void DoRoutingSerializationV2CHRoutingV2ComparisonTest(string embeddedString)
        {
            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)),
                    interpreter, Vehicle.Car);

            // create serializer.
            var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.v2.CHEdgeDataDataSourceSerializer(true);

            // serialize/deserialize.
            TagsCollectionBase metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            byte[] byteArray;
            using (var stream = new MemoryStream())
            {
                try
                {
                    routingSerializer.Serialize(stream, original, metaData);
                    byteArray = stream.ToArray();
                }
                catch (Exception)
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    throw;
                }
            }

            IBasicRouterDataSource<CHEdgeData> deserializedVersion =
                routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData);
            Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));
            Assert.IsTrue(deserializedVersion.SupportsProfile(Vehicle.Car));
            Assert.IsFalse(deserializedVersion.SupportsProfile(Vehicle.Bicycle));

            // create reference router.
            original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            var basicRouterOriginal = new CHRouter();
            Router referenceRouter = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var basicRouter = new CHRouter();
            Router router = Router.CreateCHFrom(
                deserializedVersion, basicRouter, interpreter);

            this.TestCompareAll(original, referenceRouter, router);
        }
Example #3
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.Logging.Log.RegisterListener(
                new OsmSharp.Android.UI.Log.LogTraceListener());

            // 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(
                    Scene2D.Deserialize(
                        Assembly.GetExecutingAssembly().GetManifestResourceStream(
                            @"OsmSharp.Android.UI.Sample.kempen-big/osm.pbf.scene.layered"), true)));

            var from = new GeoCoordinate(51.261203, 4.780760);
            var to = new GeoCoordinate(51.267797, 4.801362);

            var routingSerializer =
                new OsmSharp.Routing.CH.Serialization.Sorted.v2.CHEdgeDataDataSourceSerializer(false);
            TagsCollectionBase metaData = null;
            var graphDeserialized = routingSerializer.Deserialize(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.Android.UI.Sample.kempen-big.osm.pbf.routing"), out metaData, true);

            _router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());
            RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
            RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);
            Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
            RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter());
            _enumerator = route1.GetRouteEnumerable(10).GetEnumerator();

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

            _mapView = new MapView(this, new MapViewSurface(this));
            //_mapView = new MapView(this, new MapViewGLSurface(this));
            _mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent);
            _mapView.Map = map;

            _mapView.MapAllowPan = true;
            _mapView.MapAllowTilt = true;
            _mapView.MapAllowZoom = true;

            (_mapView as IMapView).AutoInvalidate = true;
            _mapView.MapMaxZoomLevel = 20;
            _mapView.MapMinZoomLevel = 10;
            _mapView.MapTilt = 0;
            _mapView.MapCenter = new GeoCoordinate(51.26371, 4.78601);
            _mapView.MapZoom = 16;

            _textView = new TextView(this);
            _textView.SetBackgroundColor(global::Android.Graphics.Color.White);
            _textView.SetTextColor(global::Android.Graphics.Color.Black);

            //Create the user interface in code
            var layout = new LinearLayout(this);
            layout.Orientation = Orientation.Vertical;
            layout.AddView(_textView);
            layout.AddView(_mapView);

            //_mapView.AddMarker(from);
            //_mapView.AddMarker(to);

            //_mapView.ZoomToMarkers();

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

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

            SetContentView (layout);
        }
Example #4
0
        public override void LoadView()
        {
            OsmSharp.Logging.Log.Enable ();
            //            OsmSharp.Logging.Log.RegisterListener(
            //                new OsmSharp.Android.UI.Log.LogTraceListener());
            base.LoadView ();

            // initialize a test-map.
            var map = new Map ();
            map.AddLayer (new LayerScene (Scene2D.Deserialize (
                Assembly.GetExecutingAssembly ().GetManifestResourceStream (
                    "OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.scene.layered"),
                        true)));

            // Perform any additional setup after loading the view, typically from a nib.
            MapView mapView = new MapView ();
            _mapView = mapView;
            //mapViewAnimator = new MapViewAnimator (mapView);
            mapView.Map = map;
            mapView.MapCenter = new GeoCoordinate(51.26371, 4.78601); // wechel
            //			mapView.MapTapEvent+= delegate(GeoCoordinate geoCoordinate) {
            //				mapView.AddMarker(geoCoordinate).TouchDown  += MapMarkerClicked;
            //			};

            mapView.MapMaxZoomLevel = 18;
            mapView.MapMinZoomLevel = 12;
            mapView.MapZoom = 16;
            mapView.MapTilt = 30;

            TagsCollectionBase metaData;
            var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.v2.CHEdgeDataDataSourceSerializer(false);
            var graphDeserialized = routingSerializer.Deserialize(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.routing"), out metaData, true);

            _router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());

            var from = new GeoCoordinate(51.261203, 4.780760);
            var to = new GeoCoordinate(51.267797, 4.801362);

            RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
            RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);
            Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
            _enumerator = route1.GetRouteEnumerable(10).GetEnumerator();

            _routeLayer = new LayerRoute(map.Projection);
            _routeLayer.AddRoute (route1);
            map.AddLayer(_routeLayer);

            View = mapView;

            mapView.AddMarker(from);
            mapView.AddMarker(to);

            RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter());
            _routeTrackerAnimator = new RouteTrackerAnimator(mapView, routeTracker, 5);

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