Ejemplo n.º 1
0
        /// <summary>
        /// Renders a LineString to the map.
        /// </summary>
        /// <param name="g">IGraphics reference</param>
        /// <param name="line">LineString to render</param>
        /// <param name="pen">Pen style used for rendering</param>
        /// <param name="map">Map reference</param>
        /// <param name="offset">Offset by which line will be moved to right</param>
        public void DrawLineString(IGraphics g, ILineString line, Pen pen, Map map, float offset)
        {
            var points = line.TransformToImage(map);

            if (points.Length > 1)
            {
                var gp = new GraphicsPath();
                if (offset != 0d)
                {
                    points = RendererHelper.OffsetRight(points, offset);
                }
                gp.AddLines(/*LimitValues(*/ points /*, ExtremeValueLimit)*/);

                g.DrawPath(pen, gp);
            }
        }
Ejemplo n.º 2
0
        private void DrawPolygonClipped(GraphicsPath gp, PointF[] polygon, int width, int height)
        {
            var clipState = DetermineClipState(polygon, width, height);

            if (clipState == ClipState.Within)
            {
                gp.AddPolygon(polygon);
            }
            else if (clipState == ClipState.Intersecting)
            {
                var clippedPolygon = RendererHelper.ClipPolygon(polygon, width, height);
                if (clippedPolygon.Length > 2)
                {
                    gp.AddPolygon(clippedPolygon);
                }
            }
        }
Ejemplo n.º 3
0
        public void DrawLabel(IGraphics g, PointF labelPoint, PointF offset, Font font, Color forecolor,
                              Brush backcolor, Pen halo, float rotation, string text, Map map,
                              LabelStyle.HorizontalAlignmentEnum alignment = LabelStyle.HorizontalAlignmentEnum.Left,
                              PointF?rotationPoint = null)
        {
            //Calculate the size of the text
            var labelSize = RendererHelper.SizeOfString(g, text, font);

            //Add label offset
            labelPoint.X += offset.X;
            labelPoint.Y += offset.Y;

            //Translate alignment to stringalignment
            StringAlignment salign;

            switch (alignment)
            {
            case LabelStyle.HorizontalAlignmentEnum.Left:
                salign = StringAlignment.Near;
                break;

            case LabelStyle.HorizontalAlignmentEnum.Center:
                salign = StringAlignment.Center;
                break;

            default:
                salign = StringAlignment.Far;
                break;
            }

            if (rotation != 0 && !float.IsNaN(rotation))
            {
                rotationPoint = rotationPoint ?? labelPoint;

                PointF pt = rotationPoint.Value;
                g.FillEllipse(Brushes.LawnGreen, (int)(pt.X - 1), (int)(pt.Y - 1), 2, 2);

                var t = g.Transform.Clone();
                g.TranslateTransform(pt.X, pt.Y);
                g.RotateTransform(rotation);
                //g.TranslateTransform(-labelSize.Width/2, -labelSize.Height/2);

                labelPoint = new PointF(labelPoint.X - pt.X,
                                        labelPoint.Y - pt.Y);

                //labelSize = new SizeF(labelSize.Width*0.74f + 1f, labelSize.Height*0.74f);
                if (backcolor != null && backcolor != Brushes.Transparent)
                {
                    g.FillRectangle(backcolor,
                                    (int)labelPoint.X, (int)labelPoint.Y,
                                    (int)labelSize.Width, (int)labelSize.Height);
                }

                var path = new GraphicsPath();
                path.AddString(text, font.FontFamily, (int)font.Style, font.Size,
                               new RectangleF(labelPoint, labelSize) /* labelPoint*/,
                               new StringFormat {
                    Alignment = salign
                } /*null*/);
                if (halo != null)
                {
                    g.DrawPath(halo, path);
                }

                g.FillPath(new SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
                g.Transform = t;
            }
            else
            {
                if (backcolor != null && backcolor != Brushes.Transparent)
                {
                    g.FillRectangle(backcolor,
                                    (int)labelPoint.X, (int)labelPoint.Y,
                                    (int)labelSize.Width, (int)labelSize.Height);
                }

                var path = new GraphicsPath();
                path.AddString(text, font.FontFamily, (int)font.Style, font.Size,
                               new RectangleF(labelPoint, labelSize) /* labelPoint*/,
                               new StringFormat {
                    Alignment = salign
                } /*null*/);
                if (halo != null)
                {
                    g.DrawPath(halo, path);
                }
                g.FillPath(new SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }