private void drawActiveNode(Graphics g, MapToClientDelegate MapToClient, Color color, int offsetX, int offsetY)
        {
            ICoordinate c = null;
            if (_geometry is Polyline)
                c = ((Polyline)_geometry).Paths[_activePatchIndex].Vertices[_activeCoordinateIndex];

            if (_geometry is Polygon)
                c = ((Polygon)_geometry).Contours[_activePatchIndex].Vertices[_activeCoordinateIndex];

            drawNodes(new ICoordinate[] { c }, g, MapToClient, color, offsetX, offsetY);
        }
        private void drawNodes(IEnumerable<ICoordinate> nodes, Graphics g, MapToClientDelegate MapToClient, Color color, int offsetX, int offsetY)
        {
            if (nodes.Count() <= 0)
                return;

            using (Pen p = new Pen(color))
            {
                Point[] points = new Point[nodes.Count()];

                int i = 0;
                foreach (ICoordinate c in nodes)
                {
                    points[i] = MapToClient(c);
                    points[i].X += offsetX;
                    points[i].Y += offsetY;
                    i++;
                }

                Rectangle[] rectangles = new Rectangle[points.Length];

                int ns = this.NodeSize;
                for (i = 0; i < points.Length; i++)
                    rectangles[i] = new Rectangle((int)points[i].X - ns,
                        (int)points[i].Y - ns, ns * 2, ns * 2);

                using (Brush b = new SolidBrush(color))
                {
                    g.FillRectangles(b, rectangles);
                }
                g.DrawRectangles(p, rectangles);
            }
        }
        /// <summary>
        /// Draws editing geometry.
        /// </summary>
        /// <param name="g">A System.Drawing.Graphics instance where to draw the geometry</param>
        /// <param name="mapToClient">A method performing map-to-screen conversion</param>
        /// <param name="offsetX">An X offset of geometry in pixels</param>
        /// <param name="offsetY">A Y offset of geometry in pixels</param>
        public void DrawEditingGeometry(Graphics g, MapToClientDelegate mapToClient, int offsetX, int offsetY)
        {
            if (_geometry == null)
                return;

            Point[] points;
            if (_antialias)
                g.SmoothingMode = SmoothingMode.AntiAlias;
            else
                g.SmoothingMode = SmoothingMode.HighSpeed;

            using (GraphicsPath path = new GraphicsPath(FillMode.Alternate))
            {
                if (_geometry is Polygon)
                {
                    path.StartFigure();
                    Polygon p = (Polygon)_geometry;
                    foreach (Contour c in p.Contours)
                    {
                        points = new Point[c.CoordinateCount];
                        for (int i = 0; i < c.CoordinateCount; i++)
                        {
                            points[i] = mapToClient(c.Vertices[i]);
                            points[i].X += offsetX;
                            points[i].Y += offsetY;
                        }
                        if (points.Length > 2)
                            path.AddPolygon(points);
                        else if (points.Length == 2)
                            path.AddLines(points);
                    }
                    path.CloseFigure();

                    using (Brush b = new SolidBrush(_fillColor))
                        g.FillPath(b, path);
                }

                if (_geometry is Polyline)
                {
                    Polyline p = (Polyline)_geometry;
                    foreach (LinePath pt in p.Paths)
                    {
                        path.StartFigure();
                        points = new Point[pt.CoordinateCount];
                        for (int i = 0; i < pt.CoordinateCount; i++)
                        {
                            points[i] = mapToClient(pt.Vertices[i]);
                            points[i].X += offsetX;
                            points[i].Y += offsetY;
                        }
                        if (points.Length > 1)
                            path.AddLines(points);
                    }
                }

                using (Pen p = new Pen(_inactivePatchColor))
                    g.DrawPath(p, path);

                if (_activePatchIndex >= 0)
                {
                    using (GraphicsPath activePath = new GraphicsPath(FillMode.Alternate))
                    {
                        activePath.StartFigure();
                        if (_geometry is Polygon)
                        {
                            Polygon p = (Polygon)_geometry;
                            Contour c = p.Contours[_activePatchIndex];

                            points = new Point[c.CoordinateCount];
                            for (int i = 0; i < c.CoordinateCount; i++)
                            {
                                points[i] = mapToClient(c.Vertices[i]);
                                points[i].X += offsetX;
                                points[i].Y += offsetY;
                            }
                            if (points.Length > 2)
                                activePath.AddPolygon(points);
                            else if (points.Length == 2)
                                activePath.AddLines(points);
                            activePath.CloseFigure();
                        }

                        if (_geometry is Polyline)
                        {
                            Polyline p = (Polyline)_geometry;
                            LinePath pt = p.Paths[_activePatchIndex];
                            points = new Point[pt.CoordinateCount];
                            for (int i = 0; i < pt.CoordinateCount; i++)
                            {
                                points[i] = mapToClient(pt.Vertices[i]);
                                points[i].X += offsetX;
                                points[i].Y += offsetY;
                            }
                            if (points.Length > 1)
                                activePath.AddLines(points);
                        }
                        using (Pen p = new Pen(_activePatchColor))
                            g.DrawPath(p, activePath);
                    }
                }

                drawNodes(GetSecondaryNodes(), g, mapToClient, _secondaryNodeColor, offsetX, offsetY);
                drawNodes(_geometry.ExtractCoordinates(), g, mapToClient, _primaryNodeColor, offsetX, offsetY);

                if (_activeCoordinateIndex >= 0 && _activePatchIndex >= 0)
                    drawActiveNode(g, mapToClient, _activeNodeColor, offsetX, offsetY);
            }
        }