Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of DrawArgs
        /// </summary>
        public MapDrawArgs(Graphics inGraphics, Rectangle clipRectangle, IMapFrame inMapFrame)
        {
            _graphics = inGraphics;
            _geoGraphics = new MapArgs(clipRectangle, inMapFrame.ViewExtents);

            _clipRectangle = clipRectangle;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This draws to the back buffer.  If the Backbuffer doesn't exist, this will create one.
        /// This will not flip the back buffer to the front.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="regions"></param>
        /// <param name="clipRectangles"></param>
        private void DrawWindows(MapArgs args, IList<Extent> regions, IList<Rectangle> clipRectangles)
        {
            Graphics g = args.Device;
            int numBounds = Math.Min(regions.Count, clipRectangles.Count);

            for (int i = 0; i < numBounds; i++)
            {
                Bitmap bmp = DataSet.GetBitmap(regions[i], clipRectangles[i].Size);
                if (bmp != null) g.DrawImage(bmp, clipRectangles[i]);
            }
            if (args.Device == null) g.Dispose();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This draws to the back buffer.  If the Backbuffer doesn't exist, this will create one.
        /// This will not flip the back buffer to the front.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="regions"></param>
        /// <param name="clipRectangles"></param>
        private void DrawWindows(MapArgs args, IList<Extent> regions, IList<Rectangle> clipRectangles)
        {
            Graphics g;
            if (args.Device != null)
            {
                g = args.Device; // A device on the MapArgs is optional, but overrides the normal buffering behaviors.
            }
            else
            {
                if (_backBuffer == null) _backBuffer = new Bitmap(_bufferRectangle.Width, _bufferRectangle.Height);
                g = Graphics.FromImage(_backBuffer);
            }
            int numBounds = Math.Min(regions.Count, clipRectangles.Count);

            for (int i = 0; i < numBounds; i++)
            {
                // For panning tiles, the region needs to be expanded.
                // This is not always 1 pixel.  When very zoomed in, this could be many pixels,
                // but should correspond to 1 pixel in the source image.

                int dx = (int)Math.Ceiling(DataSet.Bounds.AffineCoefficients[1] * clipRectangles[i].Width / regions[i].Width);
                Rectangle r = RectangleExt.ExpandBy(clipRectangles[i], dx * 2);
                if (r.X < 0) r.X = 0;
                if (r.Y < 0) r.Y = 0;
                if (r.Width > 2 * clipRectangles[i].Width) r.Width = 2 * clipRectangles[i].Width;
                if (r.Height > 2 * clipRectangles[i].Height) r.Height = 2 * clipRectangles[i].Height;
                Extent env = regions[i].Reproportion(clipRectangles[i], r);
                Bitmap bmp;
                try
                {
                    bmp = DataSet.GetBitmap(env, r);
                }
                catch
                {
                    continue;
                }
                if (bmp == null) continue;
                g.DrawImage(bmp, r);
                bmp.Dispose();
            }
            if (args.Device == null) g.Dispose();
        }
Ejemplo n.º 4
0
        public void DrawRegions(MapArgs args, List<Extent> regions)
        {
            // Assert that the map has the same size as the DotSpatial map
            var size = args.ImageRectangle.Size;
            _map.Size = size;
            
            // Make sure the map is zoomed to the same extent
            var env = Topology.GeometryConverter.ToGeoAPI(args.GeographicExtents);
            _map.ZoomToBox(env);

            // Always render the whole map to the device
            _map.RenderMap(args.Device);

            /*
             * This is not suitable because we might draw to printer/plotter 
             * which will make for a huge Image
             */
            #region
            //using (var mapImage = _map.GetMap())
            //{
            //    foreach (var region in regions)
            //    {
            //        var loc = args.ProjToPixel(region);
            //        args.Device.DrawImage(mapImage, loc, 
            //                              loc.X, loc.Y, loc.Width, loc.Height, 
            //                              GraphicsUnit.Pixel);
            //    }
            //}
            #endregion
        }
Ejemplo n.º 5
0
        // This draws the individual line features
        private void DrawFeatures(MapArgs e, IEnumerable<IFeature> features)
        {
            Graphics g = e.Device ?? Graphics.FromImage(_backBuffer);

            for (int selectState = 0; selectState < 2; selectState++)
            {
                foreach (ILineCategory category in Symbology.Categories)
                {
                    // Define the symbology based on the category and selection state
                    ILineSymbolizer ls = category.Symbolizer;
                    if (selectState == SELECTED) ls = category.SelectionSymbolizer;
                    if (ls.Smoothing)
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                    }
                    else
                    {
                        g.SmoothingMode = SmoothingMode.None;
                    }

                    Rectangle clipRect = ComputeClippingRectangle(e, ls);

                    // Determine the subset of the specified features that are visible and match the category
                    ILineCategory lineCategory = category;
                    int i = selectState;
                    Func<IDrawnState, bool> isMember = state =>
                                                       state.SchemeCategory == lineCategory &&
                                                       state.IsVisible &&
                                                       state.IsSelected == (i == 1);

                    var drawnFeatures = from feature in features
                                        where isMember(DrawingFilter[feature])
                                        select feature;

                    GraphicsPath graphPath = new GraphicsPath();
                    foreach (IFeature f in drawnFeatures)
                    {
                        BuildLineString(graphPath, DataSet.Vertex, f.ShapeIndex, e, clipRect);
                    }
                    double scale = 1;
                    if (ls.ScaleMode == ScaleMode.Geographic)
                    {
                        scale = e.ImageRectangle.Width / e.GeographicExtents.Width;
                    }

                    foreach (IStroke stroke in ls.Strokes)
                    {
                        stroke.DrawPath(g, graphPath, scale);
                    }

                    graphPath.Dispose();
                }
            }
            if (e.Device == null) g.Dispose();
        }
Ejemplo n.º 6
0
        internal static void BuildLineString(GraphicsPath path, double[] vertices, ShapeRange shpx, MapArgs args, Rectangle clipRect)
        {
            double minX = args.MinX;
            double maxY = args.MaxY;
            double dx = args.Dx;
            double dy = args.Dy;
            for (int prt = 0; prt < shpx.Parts.Count; prt++)
            {
                PartRange prtx = shpx.Parts[prt];
                int start = prtx.StartIndex;
                int end = prtx.EndIndex;
                List<double[]> points = new List<double[]>();

                for (int i = start; i <= end; i++)
                {
                    double[] pt = new double[2];
                    pt[X] = (vertices[i * 2] - minX) * dx;
                    pt[Y] = (maxY - vertices[i * 2 + 1]) * dy;
                    points.Add(pt);
                }

                List<List<double[]>> multiLinestrings;
                if (!shpx.Extent.Within(args.GeographicExtents))
                {
                    multiLinestrings = CohenSutherland.ClipLinestring(points, clipRect.Left, clipRect.Top,
                                                                      clipRect.Right, clipRect.Bottom);
                }
                else
                {
                    multiLinestrings = new List<List<double[]>>();
                    multiLinestrings.Add(points);
                }

                foreach (List<double[]> linestring in multiLinestrings)
                {
                    List<Point> intPoints = DuplicationPreventer.Clean(linestring);
                    if (intPoints.Count < 2)
                    {
                        points.Clear();
                        continue;
                    }
                    path.StartFigure();
                    Point[] pointArray = intPoints.ToArray();
                    path.AddLines(pointArray);
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// This will draw any features that intersect this region.  To specify the features
 /// directly, use OnDrawFeatures.  This will not clear existing buffer content.
 /// For that call Initialize instead.
 /// </summary>
 /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param>
 /// <param name="regions">The geographic regions to draw</param>
 public virtual void DrawRegions(MapArgs args, List<Extent> regions)
 {
     // First determine the number of features we are talking about based on region.
     List<Rectangle> clipRects = args.ProjToPixel(regions);
     if (EditMode)
     {
         List<IFeature> drawList = new List<IFeature>();
         foreach (Extent region in regions)
         {
             if (region != null)
             {
                 // Use union to prevent duplicates.  No sense in drawing more than we have to.
                 drawList = drawList.Union(DataSet.Select(region)).ToList();
             }
         }
         DrawFeatures(args, drawList, clipRects, true);
     }
     else
     {
         List<int> drawList = new List<int>();
         List<ShapeRange> shapes = DataSet.ShapeIndices;
         for (int shp = 0; shp < shapes.Count; shp++)
         {
             foreach (Extent region in regions)
             {
                 if (!shapes[shp].Extent.Intersects(region)) continue;
                 drawList.Add(shp);
                 break;
             }
         }
         DrawFeatures(args, drawList, clipRects, true);
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Appends the specified polygon to the graphics path.
        /// </summary>
        private static void BuildPolygon(double[] vertices, ShapeRange shpx, GraphicsPath borderPath, MapArgs args, SoutherlandHodgman shClip)
        {
            double minX = args.MinX;
            double maxY = args.MaxY;
            double dx = args.Dx;
            double dy = args.Dy;

            for (int prt = 0; prt < shpx.Parts.Count; prt++)
            {
                PartRange prtx = shpx.Parts[prt];
                int start = prtx.StartIndex;
                int end = prtx.EndIndex;
                var points = new List<double[]>(end - start + 1);

                for (int i = start; i <= end; i++)
                {
                    var pt = new[]
                    {
                        (vertices[i*2] - minX)*dx,
                        (maxY - vertices[i*2 + 1])*dy
                    };
                    points.Add(pt);
                }
                if (null != shClip)
                {
                    points = shClip.Clip(points);
                }
                var intPoints = DuplicationPreventer.Clean(points).ToArray();
                if (intPoints.Length < 2)
                {
                    continue;
                }

                borderPath.StartFigure();
                borderPath.AddLines(intPoints);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// This will draw any features that intersect this region.  To specify the features
 /// directly, use OnDrawFeatures.  This will not clear existing buffer content.
 /// For that call Initialize instead.
 /// </summary>
 /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param>
 /// <param name="regions">The geographic regions to draw</param>
 public void DrawRegions(MapArgs args, List<Extent> regions)
 {
     List<Rectangle> clipRects = args.ProjToPixel(regions);
     DrawWindows(args, regions, clipRects);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Appends the specified polygon to the graphics path.
        /// </summary>
        private static void BuildPolygon(double[] vertices, ShapeRange shpx, GraphicsPath borderPath, MapArgs args, SoutherlandHodgman shClip)
        {
            double minX = args.MinX;
            double maxY = args.MaxY;
            double dx = args.Dx;
            double dy = args.Dy;

            for (int prt = 0; prt < shpx.Parts.Count; prt++)
            {
                PartRange prtx = shpx.Parts[prt];
                int start = prtx.StartIndex;
                int end = prtx.EndIndex;
                List<double[]> points = new List<double[]>();

                for (int i = start; i <= end; i++)
                {
                    double[] pt = new double[2];
                    pt[X] = (vertices[i * 2] - minX) * dx;
                    pt[Y] = (maxY - vertices[i * 2 + 1]) * dy;
                    points.Add(pt);
                }
                if (null != shClip)
                {
                    points = shClip.Clip(points);
                }
                List<Point> intPoints = DuplicationPreventer.Clean(points);
                if (intPoints.Count < 2)
                {
                    points.Clear();
                    continue;
                }

                //Would be nice to figure out how to get rid of this lock
                lock (lock1)
                {
                    borderPath.StartFigure();
                    Point[] pointArray = intPoints.ToArray();
                    borderPath.AddLines(pointArray);
                }
                points.Clear();
            }
        }
Ejemplo n.º 11
0
        // This draws the individual polygon features
        private void DrawFeatures(MapArgs e, IEnumerable<IFeature> features)
        {
            List<GraphicsPath> paths;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            // First, use the coordinates to build the drawing paths
            BuildPaths(e, features, out paths);
            // Next draw all the paths using the various category symbols.
            DrawPaths(e, paths);
            sw.Stop();
            //Debug.WriteLine("Drawing time: " + sw.ElapsedMilliseconds);

            foreach (GraphicsPath path in paths)
            {
                path.Dispose();
            }
        }
Ejemplo n.º 12
0
        private void DrawFeatures(MapArgs e, List<int> indices)
        {
            var g = e.Device ?? Graphics.FromImage(BackBuffer);
            var origTransform = g.Transform;

            var minX = e.MinX;
            var maxY = e.MaxY;
            var dx = e.Dx;
            var dy = e.Dy;

            var states = DrawnStates;
            foreach (var category in Symbology.Categories)
            {
                var normalSymbol = GetSymbolizerBitmap(category.Symbolizer, e);
                var selectedSymbol = GetSymbolizerBitmap(category.SelectionSymbolizer, e);
                foreach (var index in indices)
                {
                    var state = states[index];
                    if (!state.Visible) continue;
                    var pc = state.Category as IPointCategory;
                    if (pc == null) continue;
                    if (pc != category) continue;

                    var bmp = state.Selected? selectedSymbol : normalSymbol;
                    if (bmp == null) continue;
                    var shape = DataSet.GetShape(index, false);
                    foreach (var part in shape.Range.Parts)
                    {
                        foreach (var vertex in part)
                        {
                            var pt = new Point
                            {
                                X = Convert.ToInt32((vertex.X - minX)*dx),
                                Y = Convert.ToInt32((maxY - vertex.Y)*dy)
                            };

                            var shift = origTransform.Clone();
                            shift.Translate(pt.X, pt.Y);
                            g.Transform = shift;

                            g.DrawImageUnscaled(bmp, -bmp.Width/2, -bmp.Height/2);
                        }
                    }
                }
            }


            if (e.Device == null) g.Dispose();
            else g.Transform = origTransform;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Draw features
 /// </summary>
 /// <param name="args">The GeoArgs that control how these features should be drawn.</param>
 /// <param name="indices">The features that should be drawn.</param>
 /// <param name="clipRectangles">If an entire chunk is drawn and an update is specified, this clarifies the changed rectangles.</param>
 /// <param name="useChunks">Boolean, if true, this will refresh the buffer in chunks.</param>
 public virtual void DrawFeatures(MapArgs args, List<int> indices, List<Rectangle> clipRectangles, bool useChunks)
 {
     this.DrawUsingChunks(args, indices, clipRectangles, useChunks, DrawFeatures);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// This will draw any features that intersect this region.  To specify the features
        /// directly, use OnDrawFeatures.  This will not clear existing buffer content.
        /// For that call Initialize instead.
        /// </summary>
        /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param>
        /// <param name="regions">The geographic regions to draw</param>
        public virtual void DrawRegions(MapArgs args, List<Extent> regions)
        {
            // First determine the number of features we are talking about based on region.
            var clipRects = args.ProjToPixel(regions);

            var drawList = new List<int>();
            for (var shp = 0; shp < DataSet.Count; shp++)
            {
                var pointExtent = DataSet.GetFeatureExtent(shp);
                if (regions.Any(pointExtent.Intersects))
                {
                    drawList.Add(shp);
                }
            }
            DrawFeatures(args, drawList, clipRects, true);
        }
Ejemplo n.º 15
0
        private static void BuildLineString(GraphicsPath path, double[] vertices, ShapeRange shpx, MapArgs args, Rectangle clipRect)
        {
            var minX = args.MinX;
            var maxY = args.MaxY;
            var dx = args.Dx;
            var dy = args.Dy;

            foreach (var prtx in shpx.Parts)
            {
                var points = prtx.Select(v => new Vertex((v.X - minX) * dx, (maxY - v.Y) * dy)).ToList();
                List<List<Vertex>> multiLinestrings;

                if (!shpx.Extent.Within(args.GeographicExtents))
                {
                    multiLinestrings = CohenSutherland.ClipLinestring(points, clipRect.Left, clipRect.Top,
                        clipRect.Right, clipRect.Bottom);
                }
                else
                {
                    multiLinestrings = new List<List<Vertex>> { points };
                }

                foreach (var linestring in multiLinestrings)
                {
                    var intPoints = DuplicationPreventer.Clean(linestring).ToArray();
                    if (intPoints.Length < 2) continue;

                    path.StartFigure();
                    path.AddLines(intPoints);
                }
            }
        }
Ejemplo n.º 16
0
        private void BuildPaths(MapArgs e, IEnumerable<IFeature> features, out List<GraphicsPath> borderPaths)
        {
            borderPaths = new List<GraphicsPath>();
            Rectangle clipRect = ComputeClippingRectangle(e);
            Extent drawExtents = e.PixelToProj(clipRect);
            SoutherlandHodgman shClip = new SoutherlandHodgman(clipRect);

            for (int selectState = 0; selectState < 2; selectState++)
            {
                foreach (IPolygonCategory category in Symbology.Categories)
                {
                    // Determine the subset of the specified features that are visible and match the category
                    IPolygonCategory polygonCategory = category;
                    int i = selectState;
                    Func<IDrawnState, bool> isMember = state =>
                                                       state.SchemeCategory == polygonCategory &&
                                                       state.IsVisible &&
                                                       state.IsSelected == (i == 1);

                    var drawnFeatures = from feature in features
                                        where isMember(DrawingFilter[feature])
                                        select feature;

                    GraphicsPath borderPath = new GraphicsPath();
                    foreach (IFeature f in drawnFeatures)
                    {
                        BuildPolygon(DataSet.Vertex, f.ShapeIndex, borderPath, e,
                                     drawExtents.Contains(f.Envelope) ? null : shClip);
                    }
                    borderPaths.Add(borderPath);
                }
            }
        }
Ejemplo n.º 17
0
 private static Rectangle ComputeClippingRectangle(MapArgs args)
 {
     const int maxSymbologyFuzz = 50;
     var clipRect = new Rectangle(args.ImageRectangle.Location.X, args.ImageRectangle.Location.Y, args.ImageRectangle.Width, args.ImageRectangle.Height);
     clipRect.Inflate(maxSymbologyFuzz, maxSymbologyFuzz);
     return clipRect;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// This draws to the back buffer.  If the back buffer doesn't exist, this will create one.
        /// This will not flip the back buffer to the front.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="regions"></param>
        /// <param name="clipRectangles"></param>
        private void DrawWindows(MapArgs args, IList<Extent> regions, IList<Rectangle> clipRectangles)
        {
            Graphics g;
            if (args.Device != null)
            {
                g = args.Device; // A device on the MapArgs is optional, but overrides the normal buffering behaviors.
            }
            else
            {
                if (_backBuffer == null) _backBuffer = new Bitmap(_bufferRectangle.Width, _bufferRectangle.Height);
                g = Graphics.FromImage(_backBuffer);
            }

            int numBounds = Math.Min(regions.Count, clipRectangles.Count);

            for (int i = 0; i < numBounds; i++)
            {
                using (Bitmap bmp = BitmapGetter.GetBitmap(regions[i], clipRectangles[i]))
                {
                    if (bmp != null) g.DrawImage(bmp, clipRectangles[i]);
                }
            }
            if (args.Device == null) g.Dispose();
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Draws the LiDAR data points in the currently visible map display
 /// </summary>
 /// <param name="args">Information about the map display</param>
 /// <param name="regions">Information about the visible regions</param>
 public void DrawRegions(MapArgs args, List<Extent> regions)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 20
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)
        {
            System.Windows.Threading.Dispatcher dispatcher = System.Windows.Application.Current.Dispatcher;
            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);

                    }

                }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// If useChunks is true, then this method
        /// </summary>
        /// <param name="args">The GeoArgs that control how these features should be drawn.</param>
        /// <param name="indices">The features that should be drawn.</param>
        /// <param name="clipRectangles">If an entire chunk is drawn and an update is specified, this clarifies the changed rectangles.</param>
        /// <param name="useChunks">Boolean, if true, this will refresh the buffer in chunks.</param>
        public virtual void DrawFeatures(MapArgs args, List<int> indices, List<Rectangle> clipRectangles, bool useChunks)
        {
            if (useChunks == false)
            {
                DrawFeatures(args, indices);
                return;
            }

            int count = indices.Count;
            int numChunks = (int)Math.Ceiling(count / (double)ChunkSize);

            for (int chunk = 0; chunk < numChunks; chunk++)
            {
                int numFeatures = ChunkSize;
                if (chunk == numChunks - 1) numFeatures = indices.Count - (chunk * ChunkSize);
                DrawFeatures(args, indices.GetRange(chunk * ChunkSize, numFeatures));

                if (numChunks > 0 && chunk < numChunks - 1)
                {
                    // FinishDrawing();
                    OnBufferChanged(clipRectangles);
                    Application.DoEvents();
                    // this.StartDrawing();
                }
            }
        }
Ejemplo n.º 22
0
 /// <summary>
 /// This will draw any features that intersect this region.  To specify the features
 /// directly, use OnDrawFeatures.  This will not clear existing buffer content.
 /// For that call Initialize instead.
 /// </summary>
 /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param>
 /// <param name="regions">The geographic regions to draw</param>
 public virtual void DrawRegions(MapArgs args, List<Extent> regions)
 {
     List<Rectangle> clipRects = args.ProjToPixel(regions);
     if (EditMode)
     {
         List<IFeature> drawList = new List<IFeature>();
         drawList = regions.Where(region => region != null).Aggregate(drawList, (current, region) => current.Union(DataSet.Select(region)).ToList());
         DrawFeatures(args, drawList, clipRects, true);
     }
     else
     {
         List<int> drawList = new List<int>();
         List<ShapeRange> shapes = DataSet.ShapeIndices;
         for (int shp = 0; shp < shapes.Count; shp++)
         {
             foreach (Extent region in regions)
             {
                 if (!shapes[shp].Extent.Intersects(region)) continue;
                 drawList.Add(shp);
                 break;
             }
         }
         DrawFeatures(args, drawList, clipRects, true);
     }
 }
Ejemplo n.º 23
0
        private void DrawFeatures(MapArgs e, IEnumerable<int> indices)
        {
            Graphics g = e.Device ?? Graphics.FromImage(_backBuffer);

            if (DrawnStatesNeeded)
            {
                FastDrawnState[] states = DrawnStates;
                int max = indices.Max();
                if (max >= states.Length)
                {
                    AssignFastDrawnStates();
                    states = DrawnStates;
                }
                for (int selectState = 0; selectState < 2; selectState++)
                {
                    foreach (ILineCategory category in Symbology.Categories)
                    {
                        // Define the symbology based on the category and selection state
                        ILineSymbolizer ls = category.Symbolizer;
                        if (selectState == SELECTED) ls = category.SelectionSymbolizer;
                        if (ls.Smoothing)
                        {
                            g.SmoothingMode = SmoothingMode.AntiAlias;
                        }
                        else
                        {
                            g.SmoothingMode = SmoothingMode.None;
                        }

                        // Compute a clipping rectangle that accounts for symbology
                        Rectangle clipRect = ComputeClippingRectangle(e, ls);

                        // Determine the subset of the specified features that are visible and match the category
                        ILineCategory lineCategory = category;
                        int i = selectState;

                        List<int> drawnFeatures = new List<int>();

                        foreach (int index in indices)
                        {
                            FastDrawnState state = states[index];
                            if (state.Category == lineCategory && state.Selected == (i == 1) && state.Visible)
                            {
                                drawnFeatures.Add(index);
                            }
                        }

                        GraphicsPath graphPath = new GraphicsPath();
                        foreach (int shp in drawnFeatures)
                        {
                            ShapeRange shape = DataSet.ShapeIndices[shp];
                            BuildLineString(graphPath, DataSet.Vertex, shape, e, clipRect);
                        }
                        double scale = 1;
                        if (ls.ScaleMode == ScaleMode.Geographic)
                        {
                            scale = e.ImageRectangle.Width / e.GeographicExtents.Width;
                        }

                        foreach (IStroke stroke in ls.Strokes)
                        {
                            stroke.DrawPath(g, graphPath, scale);
                        }

                        graphPath.Dispose();
                    }
                }
            }
            else
            {
                // Selection state is disabled
                // Category is only the very first category
                ILineCategory category = Symbology.Categories[0];
                ILineSymbolizer ls = category.Symbolizer;

                if (ls.Smoothing)
                {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                }
                else
                {
                    g.SmoothingMode = SmoothingMode.None;
                }

                Rectangle clipRect = ComputeClippingRectangle(e, ls);
                // Determine the subset of the specified features that are visible and match the category
                GraphicsPath graphPath = new GraphicsPath();
                foreach (int shp in indices)
                {
                    ShapeRange shape = DataSet.ShapeIndices[shp];
                    BuildLineString(graphPath, DataSet.Vertex, shape, e, clipRect);
                }
                double scale = 1;
                if (ls.ScaleMode == ScaleMode.Geographic)
                {
                    scale = e.ImageRectangle.Width / e.GeographicExtents.Width;
                }

                foreach (IStroke stroke in ls.Strokes)
                {
                    stroke.DrawPath(g, graphPath, scale);
                }

                graphPath.Dispose();
            }

            if (e.Device == null) g.Dispose();
        }
Ejemplo n.º 24
0
        // This draws the individual polygon features
        private void DrawFeatures(MapArgs e, IEnumerable<IFeature> features)
        {
            List<GraphicsPath> paths;
            // First, use the coordinates to build the drawing paths
            BuildPaths(e, features, out paths);

            // Next draw all the paths using the various category symbols.
            DrawPaths(e, paths);

            foreach (var path in paths)
            {
                path.Dispose();
            }
        }
Ejemplo n.º 25
0
 private static Rectangle ComputeClippingRectangle(MapArgs args, ILineSymbolizer ls)
 {
     // Compute a clipping rectangle that accounts for symbology
     int maxLineWidth = 2 * (int)Math.Ceiling(ls.GetWidth());
     Rectangle clipRect = new Rectangle(args.ImageRectangle.Location.X, args.ImageRectangle.Location.Y, args.ImageRectangle.Width, args.ImageRectangle.Height);
     clipRect.Inflate(maxLineWidth, maxLineWidth);
     return clipRect;
 }
Ejemplo n.º 26
0
        // This draws the individual line features
        private void DrawFeatures(MapArgs e, IEnumerable<int> indices)
        {
            if (DataSet.ShapeIndices == null) return;
            List<GraphicsPath> paths;

            // First, use the coordinates to build the drawing paths
            BuildPaths(e, indices, out paths);

            // Next draw all the paths using the various category symbols.
            DrawPaths(e, paths);

            foreach (var path in paths)
            {
                path.Dispose();
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// This will draw any features that intersect this region.  To specify the features
 /// directly, use OnDrawFeatures.  This will not clear existing buffer content.
 /// For that call Initialize instead.
 /// </summary>
 /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param>
 /// <param name="regions">The geographic regions to draw</param>
 public void DrawRegions(MapArgs args, List<Extent> regions)
 {
     List<Rectangle> clipRects = args.ProjToPixel(regions);
     for (int i = clipRects.Count - 1; i >= 0; i--)
     {
         if (clipRects[i].Width != 0 && clipRects[i].Height != 0) continue;
         regions.RemoveAt(i);
         clipRects.RemoveAt(i);
     }
     DrawWindows(args, regions, clipRects);
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Draws the GraphicsPaths.  Before we were effectively "re-creating" the same geometric
        /// </summary>
        /// <param name="e"></param>
        /// <param name="paths"></param>
        private void DrawPaths(MapArgs e, IList<GraphicsPath> paths)
        {
            Graphics g = e.Device ?? Graphics.FromImage(BackBuffer);
            int numCategories = Symbology.Categories.Count;

            if (!DrawnStatesNeeded && !EditMode)
            {
                IPolygonSymbolizer ps = Symbolizer;

                g.SmoothingMode = ps.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;
                Extent catBounds = DataSet.Extent;
                var bounds = new RectangleF
                {
                    X = Convert.ToSingle((catBounds.MinX - e.MinX) * e.Dx),
                    Y = Convert.ToSingle((e.MaxY - catBounds.MaxY) * e.Dy)
                };
                float r = Convert.ToSingle((catBounds.MaxX - e.MinX) * e.Dx);
                bounds.Width = r - bounds.X;
                float b = Convert.ToSingle((e.MaxY - catBounds.MinY) * e.Dy);
                bounds.Height = b - bounds.Y;

                foreach (IPattern pattern in ps.Patterns)
                {
                    IGradientPattern gp = pattern as IGradientPattern;
                    if (gp != null)
                    {
                        gp.Bounds = bounds;
                    }

                    pattern.FillPath(g, paths[0]);
                }

                double scale = 1;
                if (ps.ScaleMode == ScaleMode.Geographic)
                {
                    scale = e.ImageRectangle.Width / e.GeographicExtents.Width;
                }
                foreach (IPattern pattern in ps.Patterns)
                {
                    if (pattern.UseOutline)
                    {
                        pattern.DrawPath(g, paths[0], scale);
                    }
                }
            }
            else
            {
                for (int selectState = 0; selectState < 2; selectState++)
                {
                    int iCategory = 0;
                    foreach (IPolygonCategory category in Symbology.Categories)
                    {
                        Extent catBounds;
                        catBounds = CategoryExtents.Keys.Contains(category) ? CategoryExtents[category] : CalculateCategoryExtent(category);
                        if (catBounds == null) catBounds = Extent;
                        var bounds = new RectangleF
                        {
                            X = Convert.ToSingle((catBounds.MinX - e.MinX) * e.Dx),
                            Y = Convert.ToSingle((e.MaxY - catBounds.MaxY) * e.Dy)
                        };
                        float r = Convert.ToSingle((catBounds.MaxX - e.MinX) * e.Dx);
                        bounds.Width = r - bounds.X;
                        float b = Convert.ToSingle((e.MaxY - catBounds.MinY) * e.Dy);
                        bounds.Height = b - bounds.Y;

                        int index = selectState * numCategories + iCategory;
                        // Define the symbology based on the category and selection state
                        IPolygonSymbolizer ps = category.Symbolizer;
                        if (selectState == SELECTED) ps = category.SelectionSymbolizer;

                        g.SmoothingMode = ps.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;

                        foreach (IPattern pattern in ps.Patterns)
                        {
                            IGradientPattern gp = pattern as IGradientPattern;
                            if (gp != null)
                            {
                                gp.Bounds = bounds;
                            }
                            if (paths[index] != null)
                            {
                                paths[index].FillMode = FillMode.Winding;
                                pattern.FillPath(g, paths[index]);
                            }
                        }

                        double scale = 1;
                        if (ps.ScaleMode == ScaleMode.Geographic)
                        {
                            scale = e.ImageRectangle.Width / e.GeographicExtents.Width;
                        }
                        foreach (IPattern pattern in ps.Patterns)
                        {
                            if (pattern.UseOutline)
                            {
                                pattern.DrawPath(g, paths[index], scale);
                            }
                        }
                        iCategory++;
                    } // category
                } // selectState
            }

            if (e.Device == null) g.Dispose();
        }
Ejemplo n.º 29
0
        /// <summary>
        /// This will draw any features that intersect this region.  To specify the features
        /// directly, use OnDrawFeatures.  This will not clear existing buffer content.
        /// For that call Initialize instead.
        /// </summary>
        /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param>
        /// <param name="regions">The geographic regions to draw</param>
        public virtual void DrawRegions(MapArgs args, List<Extent> regions)
        {
            double minX = args.MinX;
            double maxY = args.MaxY;
            double dx = args.Dx;
            double dy = args.Dy;
            if (Double.IsInfinity(dx) || Double.IsInfinity(dy)) return;

            foreach (Extent boundingBox in regions)
            {
                Graphics g = args.Device ?? Graphics.FromImage(_backBuffer);
                Matrix origTransform = g.Transform;
                FeatureType featureType = FeatureType.Point;

                //reads the point array from the data source
                //DataSet implements or uses IShapeSource to read the points that are within the bounding box
                double[] vertices = DataSet.GetPointArray(boundingBox);

                //setup the point symbol
                Color randomColor = CreateRandomColor();
                Bitmap normalSymbol = CreateDefaultSymbol(randomColor, 4);

                //run the drawing operation
                int numPoints = vertices.Length / 2;

                for (int index = 0; index < numPoints; index++)
                {
                    Bitmap bmp = normalSymbol;

                    if (featureType == FeatureType.Point)
                    {
                        Point pt = new Point();
                        pt.X = Convert.ToInt32((vertices[index * 2] - minX) * dx);
                        pt.Y = Convert.ToInt32((maxY - vertices[index * 2 + 1]) * dy);

                        Matrix shift = origTransform.Clone();
                        shift.Translate(pt.X, pt.Y);
                        g.Transform = shift;

                        g.DrawImageUnscaled(bmp, -bmp.Width / 2, -bmp.Height / 2);
                    }
                }

                if (args.Device == null) g.Dispose();
                else g.Transform = origTransform;
            }
        }
Ejemplo n.º 30
0
        private void BuildPaths(MapArgs e, IEnumerable<int> indices, out List<GraphicsPath> paths)
        {
            paths = new List<GraphicsPath>();
            Extent drawExtents = e.GeographicExtents;
            Rectangle clipRect = e.ProjToPixel(e.GeographicExtents);
            SoutherlandHodgman shClip = new SoutherlandHodgman(clipRect);

            List<GraphicsPath> graphPaths = new List<GraphicsPath>();
            Dictionary<FastDrawnState, GraphicsPath> borders = new Dictionary<FastDrawnState, GraphicsPath>();
            for (int selectState = 0; selectState < 2; selectState++)
            {
                foreach (IPolygonCategory category in Symbology.Categories)
                {
                    FastDrawnState state = new FastDrawnState(selectState == 1, category);

                    GraphicsPath border = new GraphicsPath();
                    borders.Add(state, border);
                    graphPaths.Add(border);
                }
            }

            paths.AddRange(graphPaths);

            List<ShapeRange> shapes = DataSet.ShapeIndices;
            double[] vertices = DataSet.Vertex;

            if (ProgressReportingEnabled)
            {
                ProgressMeter = new ProgressMeter(ProgressHandler, "Building Paths", indices.Count());
            }

            if (!DrawnStatesNeeded)
            {
                FastDrawnState state = new FastDrawnState(false, Symbology.Categories[0]);

                foreach (int shp in indices)
                {
                    if (ProgressReportingEnabled) ProgressMeter.Next();
                    ShapeRange shape = shapes[shp];
                    if (!shape.Extent.Intersects(e.GeographicExtents)) return;
                    if (shp >= shapes.Count) return;
                    if (!borders.ContainsKey(state)) return;

                    BuildPolygon(vertices, shapes[shp], borders[state], e, drawExtents.Contains(shape.Extent) ? null : shClip);
                }
            }
            else
            {
                FastDrawnState[] states = DrawnStates;
                foreach (GraphicsPath borderPath in borders.Values)
                {
                    if (borderPath != null)
                    {
                        borderPath.FillMode = FillMode.Winding;
                    }
                }

                foreach (int shp in indices)
                {
                    if (ProgressReportingEnabled) ProgressMeter.Next();
                    if (shp >= shapes.Count) return;
                    if (shp >= states.Length)
                    {
                        AssignFastDrawnStates();
                        states = DrawnStates;
                    }
                    if (states[shp].Visible == false) continue;
                    ShapeRange shape = shapes[shp];
                    if (!shape.Extent.Intersects(e.GeographicExtents)) continue;
                    if (drawExtents.Contains(shape.Extent))
                    {
                        FastDrawnState state = states[shp];
                        if (!borders.ContainsKey(state)) continue;
                        BuildPolygon(vertices, shapes[shp], borders[state], e, null);
                    }
                    else
                    {
                        FastDrawnState state = states[shp];
                        if (!borders.ContainsKey(state)) continue;
                        BuildPolygon(vertices, shapes[shp], borders[state], e, shClip);
                    }
                }
            }
            if (ProgressReportingEnabled) ProgressMeter.Reset();
        }