public string GetGeoJson(BingTileQuery query) { int tileX, tileY, zoom; Metrics metrics = new Metrics(this._metricsType); metrics.Start("Global"); BoundingBoxQuery bboxQuery = BoundingBoxQuery.FromBingTileQuery(query); // Get tile coordinates BingMapsTileSystem.QuadKeyToTileXY(query.quadKey, out tileX, out tileY, out zoom); Queue <string> geoJsonQueue = new Queue <string>(); foreach (string table in query.Tables()) { string geojson = null; //bool foundInCache = false; //if (query.CacheMode != enDiskCacheMode.None) //{ // // If cacheMode is Read, see if image exists on disk // bmp = this.LoadTileFromDisc(tileX, tileY, zoom, table); // foundInCache = bmp != null; //} if (geojson == null) { DateTime start = DateTime.Now; geojson = GetGeoJson_BBox(bboxQuery, metrics, table); } //// Save to disc if image not empty and cacheMode is ReadWrite //if (query.CacheMode == enDiskCacheMode.ReadWrite // && !foundInCache // && bmp != null // && bmp.Tag == null) // this.SaveTileToDisc(tileX, tileY, zoom, table, bmp); geoJsonQueue.Enqueue(geojson); } return(geoJsonQueue.Dequeue()); }
public Bitmap GetImage(BingTileQuery query) { int tileX, tileY, zoom; Metrics metrics = new Metrics(this._metricsType); metrics.Start("Global"); BoundingBoxQuery bboxQuery = BoundingBoxQuery.FromBingTileQuery(query); // Get tile coordinates BingMapsTileSystem.QuadKeyToTileXY(query.quadKey, out tileX, out tileY, out zoom); Queue <Bitmap> bmpQueue = new Queue <Bitmap>(); foreach (string table in query.Tables()) { Bitmap bmp = null; bool foundInCache = false; if (query.CacheMode != enDiskCacheMode.None) { // If cacheMode is Read, see if image exists on disk bmp = this.LoadTileFromDisc(tileX, tileY, zoom, table); foundInCache = bmp != null; } if (bmp == null) { DateTime start = DateTime.Now; if (bboxQuery.IsBench) { bmp = GetBenchImageGeneric(bboxQuery, metrics, table, UseInMemoryCache); } else { //string test = GetGeoJson_BBox(bboxQuery, metrics, table); bmp = GetImage_BBox(bboxQuery, metrics, table); } //else // bmp = GetImageGeneric_FromDB(bboxQuery, metrics, table, false); } // Save to disc if image not empty and cacheMode is ReadWrite if (query.CacheMode == enDiskCacheMode.ReadWrite && !foundInCache && bmp != null && bmp.Tag == null) { this.SaveTileToDisc(tileX, tileY, zoom, table, bmp); } bmpQueue.Enqueue(bmp); } metrics.Stop("Global"); if (bmpQueue.Count <= 1) { Bitmap bmpOut = bmpQueue.Dequeue(); #region Calculate metrics to return. // Calculate metrics to return. switch (_metricsType) { case enMetricsType.OnlyTime: string msg = string.Empty; foreach (var kv in metrics.GetTaskTimes()) { msg += string.Format("{0}: {1,6:###,###} ms{2}", kv.Key, kv.Value.TotalMilliseconds, Environment.NewLine); } this.DrawMsgInImage(ref bmpOut, msg); break; default: break; } #endregion return(bmpOut); } else { Bitmap outBmp = bmpQueue.Dequeue(); using (Graphics g = Graphics.FromImage(outBmp)) { do { Bitmap curBmp = bmpQueue.Dequeue(); if (curBmp.Tag != null) { outBmp.Tag = curBmp.Tag; } g.DrawImageUnscaled(curBmp, 0, 0); curBmp.Dispose(); }while (bmpQueue.Count > 0); } return(outBmp); } }