コード例 #1
0
ファイル: Activity1.cs プロジェクト: pariv/samples
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // hide title bar.
            this.RequestWindowFeature(global::Android.Views.WindowFeatures.NoTitle);

            // initialize OsmSharp native handlers.
            Native.Initialize();

            // initialize map.
            var map = new Map();

            // add a preprocessed vector data file.
            var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Android.Vectors.default.map");

            map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

            // define the mapview.
            _mapView                 = new MapView(this, new MapViewSurface(this));
            _mapView.Map             = map;
            _mapView.MapMaxZoomLevel = 17; // limit min/max zoom, the vector data in this sample covers only a small area.
            _mapView.MapMinZoomLevel = 12;
            _mapView.MapTilt         = 0;
            _mapView.MapCenter       = new GeoCoordinate(51.26361, 4.78620);
            _mapView.MapZoom         = 16;
            _mapView.MapAllowTilt    = false;

            // set the map view as the default content view.
            SetContentView(_mapView);
        }
コード例 #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // initialize OsmSharp native handlers.
            Native.Initialize();

            // initialize map.
            var map = new Map();

            // add a preprocessed vector data file.
            var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"iOS.Vectors.default.map");

            map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

            // define the mapview.
            _mapView                 = new MapView();
            _mapView.Map             = map;
            _mapView.MapMaxZoomLevel = 17; // limit min/max zoom, the vector data in this sample covers only a small area.
            _mapView.MapMinZoomLevel = 12;
            _mapView.MapTilt         = 0;
            _mapView.MapCenter       = new GeoCoordinate(51.26361, 4.78620);
            _mapView.MapZoom         = 16;
            _mapView.MapAllowTilt    = false;

            View = _mapView;
        }
コード例 #3
0
        /// <summary>
        /// Tests rendering the given serialized scene.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        /// <param name="createTarget"></param>
        /// <param name="createRenderer"></param>
        /// <param name="range"></param>
        /// <param name="minZoom"></param>
        public static void TestRenderScene(CreateTarget createTarget, CreateRenderer createRenderer,
                                           Stream stream, GeoCoordinateBox box, int testCount, int range, int minZoom)
        {
            WebMercator projection = new WebMercator();

            // build a map.
            Map map = new Map();
            TagsCollectionBase metaTags;

            map.AddLayer(new LayerScene(
                             Scene2D.Deserialize(stream, true, out metaTags)));

            // build the target and renderer.
            TTarget target = createTarget.Invoke(TargetWidth, TargetHeight);
            MapRenderer <TTarget> mapRenderer = new MapRenderer <TTarget>(
                createRenderer.Invoke());

            // render the map.
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("Scene2DLayeredRendering");

            performanceInfo.Start();
            //performanceInfo.Report("Rendering {0} random images...", testCount);

            while (testCount > 0)
            {
                // randomize view.
                int zoom = minZoom;
                if (range > 1)
                { // only randomize when range is > 1
                    zoom = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(range) + minZoom;
                }
                GeoCoordinate center = box.GenerateRandomIn();
                View2D        view   = mapRenderer.Create(TargetWidth, TargetHeight, map,
                                                          (float)projection.ToZoomFactor(zoom), center, false, true);

                OsmSharp.Logging.Log.TraceEvent("Scene2DLayeredRendering", OsmSharp.Logging.TraceEventType.Information,
                                                string.Format("Rendering at z{0} l{1}.",
                                                              zoom, center));
                map.ViewChanged((float)projection.ToZoomFactor(zoom), center, view, view);

                mapRenderer.Render(target, map, view, (float)projection.ToZoomFactor(zoom));

                testCount--;
            }

            performanceInfo.Stop();
            stream.Seek(0, SeekOrigin.Begin);
        }
コード例 #4
0
        /// <summary>
        /// Initializes the View property.
        /// </summary>
        public override void LoadView()
        {
            base.LoadView();

            // initialize OsmSharp native hooks.
            Native.Initialize();

            // enable the loggging.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(new OsmSharp.iOS.UI.Log.ConsoleTraceListener());

            // initialize map.
            var map = new Map();
            // add a tile layer.
            //            map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            //            map.AddLayer(new LayerMBTile(SQLiteConnection.CreateFrom(
            //                Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.iOS.UI.Sample.kempen.mbtiles"), "map")));

            // add an online osm-data->mapCSS translation layer.
            //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter));
            // add a pre-processed vector data file.
            var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "OsmSharp.iOS.UI.Sample.default.map");

            map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

            //            var primitivesLayer = new LayerPrimitives(map.Projection);
            //            primitivesLayer.AddPoint(new GeoCoordinate(51.26371, 4.78601), 10,
            //                SimpleColor.FromKnownColor(KnownColor.Blue).Value);
            //            map.AddLayer(primitivesLayer);

            //			// define dummy from and to points.
            var from = new GeoCoordinate(51.261203, 4.780760);
            var to   = new GeoCoordinate(51.267797, 4.801362);

            //
            //			// deserialize the pre-processed graph.
            //			var routingSerializer = new CHEdgeDataDataSourceSerializer(false);
            //			TagsCollectionBase metaData = null;
            //			var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
            //				"OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.routing");
            //			var graphDeserialized = routingSerializer.Deserialize(graphStream, out metaData, true);
            //
            //			// initialize router.
            //			_router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter());
            //
            //			// resolve points.
            //			RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
            //			RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);
            //
            //			// calculate route.
            //			Route route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
            //			RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter());
            //			_enumerator = route.GetRouteEnumerable(10).GetEnumerator();
            //
            //			// add a router layer.
            //			_routeLayer = new LayerRoute(map.Projection);
            //			_routeLayer.AddRoute (route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12);
            //			map.AddLayer(_routeLayer);

            // define the mapview.
            _mapView = new MapView();
            //_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent);
            _mapView.MapAllowTilt    = false;
            _mapView.Map             = map;
            _mapView.MapMaxZoomLevel = 19;
            _mapView.MapMinZoomLevel = 0;
            _mapView.MapTilt         = 0;
            _mapView.MapCenter       = new GeoCoordinate(51.26371, 4.78601);
            _mapView.MapZoom         = 18;
            _mapView.MapInitialized += _mapView_MapInitialized;

            // add markers.
            var marker        = _mapView.AddMarker(from);
            var popupTextView = new UITextView();

            popupTextView.Text            = "Hey, this is popup text!";
            popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
            marker.AddPopup(popupTextView, 100, 100);
            marker                        = _mapView.AddMarker(to);
            popupTextView                 = new UITextView();
            popupTextView.Text            = "Hey, this is another popup text!";
            popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
            marker.AddPopup(popupTextView, 100, 100);

            this.AddMarkers();

            // add center marker.
            _centerMarker = _mapView.AddMarker(_mapView.MapCenter);

            // create the route tracker animator.
            // _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17);

            //			// simulate a number of gps-location update along the calculated route.
            //			Timer timer = new Timer(250);
            //			timer.Elapsed += new ElapsedEventHandler(TimerHandler);
            //			timer.Start();

            View = _mapView;
        }
コード例 #5
0
        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)
            {
                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.
            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--;
                }
            }
        }
コード例 #6
0
ファイル: MainActivity.cs プロジェクト: wthomson2001/OsmSharp
        /// <summary>
        /// Raises the create event.
        /// </summary>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // enable the logggin.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(new OsmSharp.Android.UI.Log.LogTraceListener());

            // initialize map.
            var map = new Map();
            // add a tile layer.
            //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            // add an online osm-data->mapCSS translation layer.
            //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter));
            // add a pre-processed vector data file.
            var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.default.map");

            map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

            // define dummy from and to points.
            var from = new GeoCoordinate(51.261203, 4.780760);
            var to   = new GeoCoordinate(51.267797, 4.801362);

            // deserialize the pre-processed graph.
            var routingSerializer       = new CHEdgeDataDataSourceSerializer(false);
            TagsCollectionBase metaData = null;
            var graphStream             = Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.kempen-big.osm.pbf.routing");
            var graphDeserialized       = routingSerializer.Deserialize(graphStream, out metaData, true);

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

            // resolve points.
            RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
            RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);

            // calculate route.
            Route        route        = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
            RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter());

            _enumerator = route.GetRouteEnumerable(10).GetEnumerator();

            // add a router layer.
            _routeLayer = new LayerRoute(map.Projection);
            _routeLayer.AddRoute(route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12);
            map.AddLayer(_routeLayer);

            // define the mapview.
            _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.MapMaxZoomLevel = 20;
            _mapView.MapMinZoomLevel = 10;
            _mapView.MapTilt         = 0;
            _mapView.MapCenter       = new GeoCoordinate(51.26371, 4.78601);
            _mapView.MapZoom         = 18;

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

            // initialize a text view to display routing instructions.
            _textView = new TextView(this);
            _textView.SetBackgroundColor(global::Android.Graphics.Color.White);
            _textView.SetTextColor(global::Android.Graphics.Color.Black);

            // add the mapview to the linear layout.
            var layout = new LinearLayout(this);

            layout.Orientation = Orientation.Vertical;
            layout.AddView(_textView);
            layout.AddView(_mapView);

            // create the route tracker animator.
            _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17);

            // simulate a number of gps-location update along the calculated route.
            Timer timer = new Timer(250);

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

            SetContentView(layout);
        }