/// <summary> /// /// </summary> /// <param name="left"></param> /// <param name="bottom"></param> /// <param name="right"></param> /// <param name="top"></param> public void LoadMap(double left, double bottom, double right, double top) { shapeQueue = new BlockingCollection <Shape>(); Task.Factory.StartNew(() => { try { string err = ""; using (var map = new OsmProvider()) { if (map.BBox(left, bottom, right, top, out err)) { foreach (var building in map.Buildings()) { shapeQueue.Add(building); } foreach (var plant in map.Natural()) { shapeQueue.Add(plant); } } else { MessageBox.Show(err, "OSM reader error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception e) { MessageBox.Show(e.Message, "OSM reader unexpected error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
/// <summary> /// Initialises a new instance of the MapControl class. /// Sets OpenStreetMap_Original and Disc Caching as the default Map and caching providers. /// Sets MinZoom of the default Map Proider as the Zoom and (0,0) as the position. /// </summary> /// <param name="batch">The SpriteBatch to use for drawing.</param> /// <param name="device">The graphicsDevice to draw the map on.</param> /// <param name="bounds">The bounds rectangle on the viewport at which the map shall be drawn.</param> public MapControl(SpriteBatch batch, GraphicsDevice device, MapRectangle bounds) { _sBatch = batch; _device = device; _map = new TiledMapProvider(OsmProvider.GetInstance(), new DiscTileCaching("cache")); _map.Zoom = _map.Provider.MinZoom; _map.Position = new MapPointLatLon(0, 0); _map.ViewBounds = bounds; // Somewhere in your LoadContent() method: // Set the pixel texture. _pixel = new Texture2D(_device, 1, 1, false, SurfaceFormat.Color); _pixel.SetData(new[] { Color.White }); }
/// <summary> /// /// </summary> /// <param name="filename"></param> public void LoadMap(string filename) { shapeQueue = new BlockingCollection <Shape>(); tokenSource = new CancellationTokenSource(); var token = tokenSource.Token;; task = Task.Factory.StartNew(() => { try { string err = ""; using (var map = new OsmProvider()) { if (map.Load(filename)) { foreach (var building in map.Buildings()) { if (token.IsCancellationRequested || building == null) { break; } shapeQueue.Add(building); } foreach (var plant in map.Natural()) { if (token.IsCancellationRequested || plant == null) { break; } shapeQueue.Add(plant); } } else { MessageBox.Show(err, "OSM reader error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception e) { MessageBox.Show(e.Message, "OSM reader unexpected error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, token); }