Beispiel #1
0
        /*
         * private static Extent FromBruTileExtent(BruTile.Extent extent)
         * {
         *  return new Extent(extent.MinX, extent.MinY, extent.MaxX, extent.MaxY);
         * }
         */

        /// <summary>
        /// This draws content from the specified geographic regions onto the specified graphics
        /// object specified by MapArgs.
        /// </summary>
        public void DrawRegions(MapArgs args, List <Extent> regions)
        {
            BruTile.Extent extent    = ToBrutileExtent(args.GeographicExtents);
            double         pixelSize = extent.Width / args.ImageRectangle.Width;

            int level = Utilities.GetNearestLevel(TileSource.Schema.Resolutions, pixelSize);
            IList <TileInfo> tiles = TileSource.Schema.GetTilesInView(extent, level);

            IList <WaitHandle> waitHandles = new List <WaitHandle>();

            foreach (TileInfo info in tiles)
            {
                if (TileCache.Find(info.Index) != null)
                {
                    continue;
                }
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                waitHandles.Add(waitHandle);
                ThreadPool.QueueUserWorkItem(GetTileOnThread,
                                             new object[] { TileSource.Provider, info, TileCache, waitHandle });
            }

            foreach (WaitHandle handle in waitHandles)
            {
                handle.WaitOne();
            }

            foreach (TileInfo info in tiles)
            {
                using (Image bitmap = Image.FromStream(new MemoryStream(TileCache.Find(info.Index))))
                {
                    PointF min = args.ProjToPixel(new Coordinate(info.Extent.MinX, info.Extent.MinY));
                    PointF max = args.ProjToPixel(new Coordinate(info.Extent.MaxX, info.Extent.MaxY));

                    min = new PointF((float)Math.Round(min.X), (float)Math.Round(min.Y));
                    max = new PointF((float)Math.Round(max.X), (float)Math.Round(max.Y));

                    args.Device.DrawImage(bitmap,
                                          new Rectangle((int)min.X, (int)max.Y, (int)(max.X - min.X), (int)(min.Y - max.Y)),
                                          0, 0, TileSource.Schema.Width, TileSource.Schema.Height,
                                          GraphicsUnit.Pixel);
                }
            }
        }
Beispiel #2
0
 private static Extent FromBruTileExtent(BruTile.Extent extent)
 {
     return(new Extent(extent.MinX, extent.MinY, extent.MaxX, extent.MaxY));
 }