/// <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> /// /// </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); }