MapGetMap Method (Boolean, MapProgress, Boolean) |
Namespace: Telogis.GeoBase
private static ManualResetEvent m_mre = new ManualResetEvent(false); private static int m_imageId = 0; public static void TestAsyncGSMap() { // asynchronous maps are only used when fetching from GeoStream Repository.Default = new GeoStreamRepository(...); Map map = new Map(new LatLon(34, -118), 600, 600, 10); int imageId = m_imageId++; bool done; // call GetMap with isAsync set to true. MapProgress is our callback Image image = new Bitmap(map.GetMap(true, MapProgress, out done)); // we are saving the map image, even if it is incomplete image.Save(string.Format(@"C:\Users\User\Documents\AsyncMap\{0}.bmp", imageId)); // done indicates whether the entire map was returned. // Block the current thread if we do not have a complete map. if (!done) { m_mre.WaitOne(); } } // MapProgress is our callback -- it is called whenever more tiles are available public static void MapProgress(IMap caller, bool isComplete) { int imageId = m_imageId++; bool done; // Inside our callback, call GetMap again to fetch the updated map image. // Pass in this callback so that we can be called recursively // when more tiles are available. Image image = new Bitmap(caller.GetMap(true, MapProgress, out done)); image.Save(string.Format(@"C:\Users\User\Documents\AsyncMap\{0}.bmp", imageId)); // When we are finally called with all tiles, set the ManualResetEvent // so that our waiting thread can continue. if (done) { m_mre.Set(); } }