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 tile Layer. // WARNING: Always look at usage policies! // WARNING: Don't use my tiles, it's a free account and will shutdown when overused! map.AddLayer(new LayerTile("http://a.tiles.mapbox.com/v3/osmsharp.i8ckml0l/{0}/{1}/{2}.png")); // define the mapview. _mapView = new MapView(this, new MapViewSurface(this)); _mapView.Map = map; _mapView.MapMaxZoomLevel = 18; // limit min/max zoom. _mapView.MapMinZoomLevel = 0; _mapView.MapTilt = 0; _mapView.MapCenter = new GeoCoordinate(21.38, -157.782); _mapView.MapZoom = 12; _mapView.MapAllowTilt = false; // set the map view as the default content view. SetContentView(_mapView); }
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; }
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 MBTiles Layer. // any stream will do or any path on the device to a MBTiles SQLite databas // in this case the data is taken from the resource stream, written to disk and then opened. map.AddLayer(new LayerMBTile(SQLiteConnection.CreateFrom( Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Android.MBTiles.kempen.mbtiles"), "map"))); // define the mapview. _mapView = new MapView(this, new MapViewSurface(this)); _mapView.Map = map; _mapView.MapMaxZoomLevel = 17; // limit min/max zoom because MBTiles sample only contains a small portion of a map. _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); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.RequestWindowFeature(global::Android.Views.WindowFeatures.NoTitle); var map = new Map(); map.AddLayer( new LayerMBTile( SQLiteConnection.CreateFrom( Assembly.GetExecutingAssembly() .GetManifestResourceStream(@"LainLadangLainBelalang.kempen.mbtiles"), "map"))); var mvs = new MapViewSurface(this); _mv = new MapView(this, mvs) { Map = map, MapMaxZoomLevel = 17, MapMinZoomLevel = 12, MapTilt = 0, MapCenter = new GeoCoordinate(51.26361, 4.78620), MapZoom = 16, MapAllowTilt = false }; SetContentView(_mv); }
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); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.RequestWindowFeature(global::Android.Views.WindowFeatures.NoTitle); Native.Initialize(); var map = new Map(); map.AddLayer(new LayerTile("https://a.tiles.mapbox.com/v4/yayapiyik.ong4bh3p/page.html?access_token=pk.eyJ1IjoieWF5YXBpeWlrIiwiYSI6ImNpaXE1Ym9ycDAxenh1ZGtuMGM4aXZsY3AifQ.eabfA1EaL4f_Z_QgMEcl-g")); /* map.AddLayer(new LayerTile("https://a.tiles.mapbox.com/v4/yayapiyik.ong4bh3p/page.html?access_token=pk.eyJ1IjoieWF5YXBpeWlrIiwiYSI6ImNpaXE1Ym9ycDAxenh1ZGtuMGM4aXZsY3AifQ.eabfA1EaL4f_Z_QgMEcl-g#17/-6.22325/106.65267")); */ mv = new MapView(this, new MapViewSurface(this)) { Map = map, MapMaxZoomLevel = 18, MapMinZoomLevel = 0, MapTilt = 0, MapCenter = new GeoCoordinate(-6.22325, 106.65267), MapZoom = 12, MapAllowTilt = false }; SetContentView(mv); }
public override void ViewDidLoad() { base.ViewDidLoad(); // initialize OsmSharp native hooks. Native.Initialize(); // initialize map. var map = new Map(); // add tile Layer. // WARNING: Always look at usage policies! // WARNING: Don't use my tiles, it's a free account and will shutdown when overused! map.AddLayer(new LayerTile("http://a.tiles.mapbox.com/v3/osmsharp.i8ckml0l/{0}/{1}/{2}.png")); // define the mapview. _mapView = new MapView(); _mapView.Map = map; _mapView.MapMaxZoomLevel = 18; // limit min/max zoom. _mapView.MapMinZoomLevel = 0; _mapView.MapTilt = 0; _mapView.MapCenter = new GeoCoordinate(21.38, -157.782); _mapView.MapZoom = 12; _mapView.MapAllowTilt = false; View = _mapView; }
/// <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; } }
/// <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; }
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; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // hide title bar. this.RequestWindowFeature(global::Android.Views.WindowFeatures.NoTitle); // initialize map. var map = new Map(); // add a preprocessed vector data file. //var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Android.Demo.default.map"); //map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true))); //OsmSharp.Osm.Data.Memory.MemoryDataSource dataSource; //using (var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Android.Demo.map1.osm")) //{ // dataSource = OsmSharp.Osm.Data.Memory.MemoryDataSource.CreateFromXmlStream(sceneStream); //} string path = Assembly.GetExecutingAssembly().GetName().Name; StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(path + ".EmbeddedResources.default.mapcss")); string test = streamReader.ReadToEnd(); StyleInterpreter styleInterpreter = new OsmSharp.UI.Map.Styles.MapCSS.MapCSSInterpreter(test); map.AddLayerOsm(OsmSharp.Osm.Data.Memory.MemoryDataSource.CreateFromXmlStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(path + ".EmbeddedResources.map.osm")), styleInterpreter); //var r2d = new CanvasRenderer2D(); //var renderer = new OsmSharp.UI.Map.MapRenderer<Canvas>(r2d); //var view = OsmSharp.UI.Renderer.View2D.CreateFromBounds(dataSource.BoundingBox.TopLeft.Latitude, dataSource.BoundingBox.TopLeft.Longitude, // dataSource.BoundingBox.BottomRight.Latitude, dataSource.BoundingBox.BottomRight.Longitude); //map.ViewChanged(16, new OsmSharp.Math.Geo.GeoCoordinate(view.Center), null, view); // define the mapview. var mapViewSurface = new MapViewSurface(this); mapViewSurface.MapScaleFactor = 2; _mapView = new MapView(this, mapViewSurface); _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.MapCenter = new GeoCoordinate(30.538079, 114.4159972); _mapView.MapZoom = 16; _mapView.MapAllowTilt = false; // set the map view as the default content view. SetContentView(_mapView); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // enable the logging. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener(new OsmSharp.Android.UI.Log.LogTraceListener()); // hide title bar. this.RequestWindowFeature(global::Android.Views.WindowFeatures.NoTitle); // initialize OsmSharp native handlers. Native.Initialize(); // initialize router. RouterFacade.Initialize(); // initialize map. var map = new Map(); // add tile Layer. // WARNING: Always look at usage policies! // WARNING: Don't use my tiles, it's a free account and will shutdown when overused! map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png")); // define route layer. _routeLayer = new LayerRoute(map.Projection); map.AddLayer(_routeLayer); // define the mapview. var surface = new MapViewSurface(this); _mapView = new MapView(this, surface); _mapView.Map = map; _mapView.MapMaxZoomLevel = 18; _mapView.MapMinZoomLevel = 0; _mapView.MapTilt = 0; _mapView.MapCenter = new GeoCoordinate(51.2631, 4.7872); _mapView.MapZoom = 16; _mapView.MapAllowTilt = false; _mapView.MapTapEvent += _mapView_MapTapEvent; // set the map view as the default content view. SetContentView(_mapView); }
private void InitializeRouting(OsmSharp.UI.Map.Map map) { //var osmInterpreter = new OsmRoutingInterpreter(); //_router = Router.CreateLiveFrom(new XmlOsmStreamSource(new FileInfo(@"c:\OSM\bin\wechel.osm").OpenRead()), // osmInterpreter); // creates a new interpreter. var interpreter = new OsmRoutingInterpreter(); // var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true); var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource( new FileInfo(@"c:\OSM\bin\wechel.osm").OpenRead()), interpreter, Vehicle.Car); //byte[] byteArray; //var stream = new MemoryStream(); //using (stream) //{ // try // { // routingSerializer.Serialize(stream, original); // byteArray = stream.ToArray(); // } // catch (Exception) // { // throw; // } //} //stream = new MemoryStream(byteArray); //Stream stream = new FileInfo(@"c:\OSM\bin\test.osm.pbf.routing.3").OpenRead(); //IBasicRouterDataSource<CHEdgeData> deserializedVersion = // routingSerializer.Deserialize(stream); var basicRouter = new CHRouter(); _router = Router.CreateCHFrom( original, basicRouter, interpreter); _routeLayer = new LayerRoute(map.Projection); map.AddLayer(_routeLayer); }
/// <summary> /// Renders the given data onto a 100x100 image using bounds around null-island (1,1,-1,-1) and the MapCSS definition. /// </summary> /// <param name="dataSource"></param> /// <param name="mapCSS"></param> /// <returns></returns> private Bitmap Render(IDataSourceReadOnly dataSource, string mapCSS) { // create projection. WebMercator projection = new WebMercator(); double[] topLeft = projection.ToPixel(new Math.Geo.GeoCoordinate(1, 1)); double[] bottomRight = projection.ToPixel(new Math.Geo.GeoCoordinate(-1, -1)); // create view (this comes down to (1,1,-1,-1) for a size of 100x100). View2D view = View2D.CreateFromBounds(bottomRight[1], topLeft[0], topLeft[1], bottomRight[0]); //View2D view = View2D.CreateFrom(0, 0, 100, 100, 1.0 / 200.0, false, true); // create graphics Bitmap rendering = new Bitmap(100, 100); Graphics renderingGraphics = Graphics.FromImage(rendering); renderingGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; renderingGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; renderingGraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; renderingGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // create renderer. GraphicsRenderer2D graphicsRenderer = new GraphicsRenderer2D(); MapRenderer <Graphics> renderer = new MapRenderer <Graphics>(graphicsRenderer); // create map. OsmSharp.UI.Map.Map map = new OsmSharp.UI.Map.Map(); map.AddLayer(new LayerOsm(dataSource, new MapCSSInterpreter(mapCSS), projection)); // notify the map that there was a view change! map.ViewChanged((float)view.CalculateZoom(100, 100), new Math.Geo.GeoCoordinate(0, 0), view); // ... and finally do the actual rendering. renderer.Render(Graphics.FromImage(rendering), map, view); //rendering.Save(@"c:\temp\rendering.bmp"); return(rendering); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.RequestWindowFeature(global::Android.Views.WindowFeatures.NoTitle); var map = new Map(); var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"LainLadangLainBelalang.default.map"); map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true))); var mvs = new MapViewSurface(this); _mv = new MapView(this, mvs) { Map = map, MapMaxZoomLevel = 17, MapMinZoomLevel = 12, MapTilt = 0, MapCenter = new GeoCoordinate(51.26361, 4.78620), MapZoom = 16, MapAllowTilt = false }; SetContentView(_mv); }
/// <summary> /// Initializes a new instance of the <see cref="OsmSharp.iOS.UI.MapView"/> class. /// </summary> /// <param name="mapCenter">Map center.</param> /// <param name="map">Map.</param> /// <param name="mapTilt">Map tilt.</param> /// <param name="defaultZoom">Default zoom.</param> public MapView(GeoCoordinate mapCenter, Map map, Degree mapTilt, float defaultZoom) { this.Initialize(mapCenter, map, mapTilt, defaultZoom); }
/// <summary> /// Tests rendering the given serialized scene. /// </summary> /// <param name="stream"></param> /// <param name="box"></param> /// <param name="testCount"></param> public static void TestRenderScene(Stream stream, GeoCoordinateBox box, int testCount) { WebMercator projection = new WebMercator(); // build a map. Map map = new Map(); IScene2DPrimitivesSource sceneSource = Scene2DLayered.Deserialize(stream, true); LayerScene layerScene = map.AddLayerScene(sceneSource); // build the target to render to. Bitmap imageTarget = new Bitmap(TargetWidth, TargetHeight); Graphics target = Graphics.FromImage(imageTarget); target.SmoothingMode = SmoothingMode.HighQuality; target.PixelOffsetMode = PixelOffsetMode.HighQuality; target.CompositingQuality = CompositingQuality.HighQuality; target.InterpolationMode = InterpolationMode.HighQualityBicubic; MapRenderer<Graphics> mapRenderer = new MapRenderer<Graphics>( new GraphicsRenderer2D()); // render the map. PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("Scene2DLayeredRendering"); performanceInfo.Start(); performanceInfo.Report("Rendering {0} random images...", testCount); while (testCount > 0) { // randomize view. int zoom = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 10; GeoCoordinate center = box.GenerateRandomIn(); View2D view = mapRenderer.Create(TargetWidth, TargetHeight, map, (float)projection.ToZoomFactor(zoom), center, false, true); layerScene.ViewChanged(map, (float)projection.ToZoomFactor(zoom), center, view); mapRenderer.Render(target, map, view); if (WriteResults) { imageTarget.Save(Guid.NewGuid().ToString() + ".png", ImageFormat.Png); } testCount--; } performanceInfo.Stop(); }
/// <summary> /// Called when the view on the map has changed. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> public void ViewChanged(Map map, float zoomFactor, GeoCoordinate center, View2D view) { }
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 (); }
/// <summary> /// Diposes of all resources associated with this object. /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { if (disposing == true) { //someone wants the deterministic release of all resources //Let us release all the managed resources } else { // Do nothing, no one asked a dispose, the object went out of // scope and finalized is called so lets next round of GC // release these resources } // Release the unmanaged resource in any case as they will not be // released by GC this._cacheRenderer = null; if (this._offScreenBuffer != null) { // dispose of the map view surface. this._offScreenBuffer.Dispose(); this._offScreenBuffer = null; } if (this._onScreenBuffer != null) { // dispose of the map view surface. this._onScreenBuffer.Dispose(); this._onScreenBuffer = null; } if (this._mapViewAnimator != null) { _mapViewAnimator.Stop(); _mapViewAnimator = null; } if (this._map != null) { this._map = null; } }
/// <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) { // register the default listener. (this as IInvalidatableMapSurface).RegisterListener(new DefaultTrigger(this)); // enable all interactions by default. this.MapAllowPan = true; this.MapAllowTilt = true; this.MapAllowZoom = true; // 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; _map.MapChanged += MapChanged; _doubleTapAnimator = new MapViewAnimator(this); this.BackgroundColor = UIColor.White; this.UserInteractionEnabled = true; 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 = (float)this.ContentScaleFactor; // create the cache renderer. _cacheRenderer = new MapRenderer<CGContextWrapper>( new CGContextRenderer(_scaleFactor)); _backgroundColor = SimpleColor.FromKnownColor(KnownColor.White).Value; }
/// <summary> /// Initializes the View property. /// </summary> public override void LoadView() { base.LoadView (); // enable the logggin. 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")); // 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.kempen-big.osm.pbf.scene.layered"); 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.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.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); // 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; }
/// <summary> /// Renders the given data onto a 100x100 image using bounds around null-island (1,1,-1,-1) and the MapCSS definition. /// </summary> /// <param name="dataSource"></param> /// <param name="mapCSS"></param> /// <returns></returns> private Bitmap Render(IDataSourceReadOnly dataSource, string mapCSS) { // create projection. WebMercator projection = new WebMercator(); double[] topLeft = projection.ToPixel(new Math.Geo.GeoCoordinate(1, 1)); double[] bottomRight = projection.ToPixel(new Math.Geo.GeoCoordinate(-1, -1)); // create view (this comes down to (1,1,-1,-1) for a size of 100x100). View2D view = View2D.CreateFromBounds(bottomRight[1], topLeft[0], topLeft[1], bottomRight[0]); //View2D view = View2D.CreateFrom(0, 0, 100, 100, 1.0 / 200.0, false, true); // create graphics Bitmap rendering = new Bitmap(100, 100); Graphics renderingGraphics = Graphics.FromImage(rendering); renderingGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; renderingGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; renderingGraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; renderingGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // create renderer. GraphicsRenderer2D graphicsRenderer = new GraphicsRenderer2D(); MapRenderer<Graphics> renderer = new MapRenderer<Graphics>(graphicsRenderer); // create map. OsmSharp.UI.Map.Map map = new OsmSharp.UI.Map.Map(); map.AddLayer(new LayerOsm(dataSource, new MapCSSInterpreter(mapCSS), projection)); // notify the map that there was a view change! map.ViewChanged((float)view.CalculateZoom(100, 100), new Math.Geo.GeoCoordinate(0, 0), view); // ... and finally do the actual rendering. renderer.Render(Graphics.FromImage(rendering), map, view); //rendering.Save(@"c:\temp\rendering.bmp"); return rendering; }
/// <summary> /// Raises the create event. /// </summary> /// <param name="bundle">Bundle.</param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // hide title bar. this.RequestWindowFeature(global::Android.Views.WindowFeatures.NoTitle); // initialize map. var map = new Map(); map.AddLayer(new LayerMBTile(OsmSharp.Android.UI.Data.SQLite.SQLiteConnection.CreateFrom( Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.kempen.mbtiles"), "map"))); // add a tile layer. //var layer = new LayerTile(@"http://a.tiles.mapbox.com/v3/osmsharp.i8ckml0l/{0}/{1}/{2}.png"); //map.AddLayer(layer); //layer.IsVisible = false; //map.AddLayer(new LayerTile(@"http://a.tiles.mapbox.com/v3/osmsharp.i8ckml0l/{0}/{1}/{2}.png")); //map.AddLayerGpx(Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.regression1.gpx")); // // add an on-line osm-data->mapCSS translation layer. //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter)); // add a preprocessed 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 preprocessed graph. //var routingSerializer = new CHEdgeDataDataSourceSerializer(); //var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.kempen-big.osm.pbf.routing"); //var graphDeserialized = routingSerializer.Deserialize(graphStream, true); //// initialize router. //_router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter()); //// resolve points. //var routerPoint1 = _router.Resolve(Vehicle.Car, from); //var routerPoint2 = _router.Resolve(Vehicle.Car, to); //// calculate route. //var route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); //// 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.MapTapEvent += _mapView_MapTapEvent; _mapView.Map = map; //_mapView.MapMaxZoomLevel = 20; //_mapView.MapMinZoomLevel = 10; _mapView.MapTilt = 0; _mapView.MapCenter = new GeoCoordinate(51.261203, 4.780760); _mapView.MapZoom = 16; _mapView.MapAllowTilt = false; _mapView.MapTouchedUp += _mapView_MapTouchedUp; _mapView.MapTouched += _mapView_MapTouched; _mapView.MapTouchedDown += _mapView_MapTouchedDown; // AddMarkers(); // AddControls(); // 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 RelativeLayout(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 mapzoom change every 5 seconds. //Timer timer = new Timer(5000); //timer.Elapsed += new ElapsedEventHandler(TimerHandler); //timer.Start(); _centerMarker = _mapView.AddMarker(_mapView.MapCenter); _mapView.MapInitialized += _mapView_MapInitialized; SetContentView(layout); }
/// <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); }
/// <summary> /// Creates a new rendering instance. /// </summary> /// <param name="cache">The cache.</param> public RenderingInstance(TileCache cache) { _targetsPerScale = new Dictionary<int, Tuple<Bitmap, Graphics>>(); _renderer = new MapRenderer<Graphics>(new GraphicsRenderer2D()); _map = new Map(new WebMercator()); _cache = cache; }
public override void LoadView() { OsmSharp.Logging.Log.Enable (); base.LoadView (); // initialize a test-map. var map = new Map (); map.AddLayer (new LayerScene (Scene2DLayered.Deserialize ( Assembly.GetExecutingAssembly ().GetManifestResourceStream ("OsmSharp.iOS.UI.Sample.wvl.map"), 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.158075, 2.961545); // gistel // mapView.MapTapEvent+= delegate(GeoCoordinate geoCoordinate) { // mapView.AddMarker(geoCoordinate).TouchDown += MapMarkerClicked; // }; mapView.MapMaxZoomLevel = 18; mapView.MapMinZoomLevel = 12; mapView.MapZoom = 16; mapView.MapTilt = 30; var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); var graphDeserialized = routingSerializer.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.iOS.UI.Sample.wvl.routing"), true); _router = Router.CreateCHFrom( graphDeserialized, new CHRouter(graphDeserialized), new OsmRoutingInterpreter()); // long before = DateTime.Now.Ticks; // // var routeLocations = new GeoCoordinate[] { // new GeoCoordinate (50.8247730, 2.7524706), // new GeoCoordinate (50.8496394, 2.7301512), // new GeoCoordinate (50.8927741, 2.6138545), // new GeoCoordinate (50.8296363, 2.8869437) // }; // // var routerPoints = new RouterPoint[routeLocations.Length]; // for (int idx = 0; idx < routeLocations.Length; idx++) { // routerPoints [idx] = router.Resolve (Vehicle.Car, routeLocations [idx]); // // mapView.AddMarker (routeLocations [idx]); // } // OsmSharp.Routing.TSP.RouterTSPWrapper<RouterTSPAEXGenetic> tspRouter = new OsmSharp.Routing.TSP.RouterTSPWrapper<RouterTSPAEXGenetic> ( // new RouterTSPAEXGenetic (10, 20), router); // // Route route = tspRouter.CalculateTSP (Vehicle.Car, routerPoints); // // long after = DateTime.Now.Ticks; // // OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information,"Routing & TSP in {0}ms", // new TimeSpan (after - before).TotalMilliseconds); // 51.160477" lon="2.961497 GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545); GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793); //GeoCoordinate point1 = new GeoCoordinate(51.159132, 2.958755); //GeoCoordinate point2 = new GeoCoordinate(51.160477, 2.961497); RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, point1); RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, point2); Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); _enumerator = route1.GetRouteEnumerable(10).GetEnumerator(); //List<Instruction> instructions = InstructionGenerator.Generate(route1, new OsmRoutingInterpreter()); // _routeLayer = new LayerRoute(map.Projection); _routeLayer.AddRoute (route1); map.AddLayer(_routeLayer); View = mapView; mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); mapView.AddMarker(point1); mapView.AddMarker(point2); mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); // // //mapView.ZoomToMarkers(); //GeoCoordinateBox box = new GeoCoordinateBox (new GeoCoordinate[] { point1, point2 }); // mapView.MapTapEvent += delegate(GeoCoordinate geoCoordinate) { //_routeTrackerAnimator.Track(box.GenerateRandomIn()); //_mapView.AddMarker(geoCoordinate).Click += new EventHandler(MainActivity_Click); //mapViewAnimator.Stop(); //mapViewAnimator.Start(geoCoordinate, 15, new TimeSpan(0, 0, 2)); }; RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter()); _routeTrackerAnimator = new RouteTrackerAnimator(mapView, routeTracker, 5); // // Timer timer = new Timer (150); // timer.Elapsed += new ElapsedEventHandler (TimerHandler); // timer.Start (); // // Task.Factory.StartNew (() => { // System.Threading.Thread.Sleep(200); // do something. // InvokeOnMainThread (() => { // mapView.ZoomToMarkers (); // }); // }); // }
/// <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); }
/// <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://192.168.43.155:1234/default/{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.2633, 4.7853); _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; }
private RenderedMap(Map map) { _map = map; Zoom = 16; }
/// <summary> /// Called when the view on the map has changed. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> /// <param name="extraView"></param> protected internal override void ViewChanged(Map map, float zoomFactor, GeoCoordinate center, View2D view, View2D extraView) { // all data is preloaded for now. // when displaying huge amounts of GPX-data use another approach. }
/// <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.kempen-big.osm.pbf.scene.layered"); 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 as IMapView).AutoInvalidate = true; _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, 18); // simulate a number of gps-location update along the calculated route. Timer timer = new Timer(500); timer.Elapsed += new ElapsedEventHandler(TimerHandler); timer.Start(); SetContentView (layout); }