Пример #1
0
 public static void Render(Graphics graphics, LineString line, Pen pen, IViewport viewport)
 {
     if (line.Vertices.Count > 1)
     {
         var points = GeometryRenderer.WorldToScreenGDI(line, viewport);
         graphics.DrawLines(pen, points);
     }
 }
Пример #2
0
        public static void DrawPolygon(Graphics graphics, Polygon pol, Brush brush, Pen pen, IViewport viewport)
        {
            if (pol.ExteriorRing == null)
            {
                return;
            }
            if (pol.ExteriorRing.Vertices.Count <= 2)
            {
                return;
            }

            //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
            var gp = new GraphicsPath();

            //Add the exterior polygon
            var points = GeometryRenderer.WorldToScreenGDI(pol.ExteriorRing, viewport);

            if (points.Length > 2)
            {
                gp.AddPolygon(points);
            }
            //Add the interior polygons (holes)
            foreach (LinearRing linearRing in pol.InteriorRings)
            {
                var interiorPoints = GeometryRenderer.WorldToScreenGDI(linearRing, viewport);
                if (interiorPoints.Length > 2)
                {
                    gp.AddPolygon(interiorPoints);
                }
            }

            if (gp.PointCount == 0)
            {
                return;
            }

            // Only render inside of polygon if the brush isn't null or isn't transparent
            if (brush != null && brush != Brushes.Transparent)
            {
                graphics.FillPath(brush, gp);
            }
            // Create an outline if a pen style is available
            if (pen != null)
            {
                graphics.DrawPath(pen, gp);
            }
        }