Пример #1
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;
        }
Пример #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 create event.
        /// </summary>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

//			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.osm.pbf.routing.ch"), true);
////
//			_router = Router.CreateCHFrom(
//				graphDeserialized, new CHRouter(graphDeserialized),
//				new OsmRoutingInterpreter());

//
//			//GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545);
//			//GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793);
//			//GeoCoordinate point3 = new GeoCoordinate(51.175967, 2.93733);
//			GeoCoordinate point1 = new GeoCoordinate (50.885726, 3.253426);
//			//GeoCoordinate point2 = new GeoCoordinate (50.88602, 3.218149);
//			GeoCoordinate point2 = new GeoCoordinate (51.1515, 2.9563);
//			GeoCoordinate point3 = new GeoCoordinate(51.34643, 3.28837);
//
//			OsmSharpRoute route1 = router.Calculate(Vehicle.Car,
//			                                       router.Resolve(Vehicle.Car, point1),
//			                                       router.Resolve(Vehicle.Car, point2));
//
//			OsmSharpRoute route2 = router.Calculate(Vehicle.Car,
//			                                       router.Resolve(Vehicle.Car, point1),
//			                                       router.Resolve(Vehicle.Car, point3));
//
//			OsmSharpRoute route3 = router.Calculate(Vehicle.Car,
//			                                        router.Resolve(Vehicle.Car, point2),
//			                                        router.Resolve(Vehicle.Car, point3));
////
////			OsmSharpRoute route = router.Calculate(Vehicle.Car,
////			                                       router.Resolve(Vehicle.Car, new GeoCoordinate(51.15136, 3.19462)),
////			                                       router.Resolve(Vehicle.Car, new GeoCoordinate(51.075023, 3.096632)));
//////			route = router.Calculate(Vehicle.Car,
//////			                         router.Resolve(Vehicle.Car, new GeoCoordinate(51.075023, 3.096632)),
//////			                         router.Resolve(Vehicle.Car, new GeoCoordinate(51.15136, 3.19462)));
////			route = router.Calculate(Vehicle.Car,
////			                         router.Resolve(Vehicle.Car, new GeoCoordinate(51.15136, 3.19462)),
////			                         router.Resolve(Vehicle.Car, new GeoCoordinate(51.075023, 3.096632)));
            _routeLayer = new LayerOsmSharpRoute(map.Projection);
//			osmSharpLayer.AddRoute (route1, SimpleColor.FromKnownColor(KnownColor.Blue).Value);
//			osmSharpLayer.AddRoute (route2, SimpleColor.FromKnownColor(KnownColor.Red).Value);
//			osmSharpLayer.AddRoute (route3, SimpleColor.FromKnownColor(KnownColor.YellowGreen).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);

            //var mapGLView = new MapGLView(this);

            var mapLayout = new MapView(this);

            mapLayout.Map = map;

            mapLayout.MapMaxZoomLevel = 20;
            mapLayout.MapMinZoomLevel = 12;
            //var mapView = new MapGLView (this);
            mapLayout.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);
            mapLayout.MapZoomLevel = 15;
            mapLayout.MapTapEvent += delegate(GeoCoordinate geoCoordinate) {
                mapLayout.AddMarker(geoCoordinate).Click += new EventHandler(MapMarkerClicked);
            };

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

            //layout.Orientation = Orientation.Vertical;

            //layout.AddView(mapGLView);
            layout.AddView(mapLayout);

//			mapLayout.AddMarker (new GeoCoordinate (51.26337, 4.78739)).Click += new EventHandler (MapMarkerClicked);
//			mapLayout.AddMarker (new GeoCoordinate (51.26785, 4.78025)).Click += new EventHandler (MapMarkerClicked);

            SetContentView(layout);
        }