Esempio n. 1
0
        private unsafe void DrawContour(IDrawArgs drawArgs, ContourLine cntLine, ContourClass cntClass, ICanvas canvas)
        {
            if (!cntClass.IsDisplay)
            {
                return;
            }
            ICoordinateTransform tran = canvas.CoordTransform;
            int nCount = cntLine.Count;

            PointF[] pts       = new PointF[nCount];
            GCHandle dstHandle = GCHandle.Alloc(pts, GCHandleType.Pinned);
            GCHandle srcHandle = GCHandle.Alloc(cntLine.Points, GCHandleType.Pinned);

            try
            {
                MemoryCopy(dstHandle.AddrOfPinnedObject(), srcHandle.AddrOfPinnedObject(), nCount << _pointfSize); // nCount * sizeof(PointF)
                QuickTransform quickTran = drawArgs.QuickTransformArgs;
                fixed(PointF *ptr0 = pts)
                {
                    PointF *ptr = ptr0;

                    for (int i = 0; i < nCount; i++, ptr++)
                    {
                        quickTran.Transform(ptr);
                    }
                }
                Graphics g = drawArgs.Graphics as Graphics;
                //
                if (_isUseCurveRender)
                {
                    g.DrawCurve(cntClass.Pen, pts, _tension);
                }
                else
                {
                    _grahpicPath.Reset();
                    _grahpicPath.AddLines(pts);
                    g.DrawPath(cntClass.Pen, _grahpicPath);
                }
                //
                if (_isLabel)
                {
                    if (_isCheckConflicting)
                    {
                        if (_conflictor.IsConflicted(pts[0], cntClass.LabelBuffer.Size))
                        {
                            return;
                        }
                        _conflictor.HoldPosition(pts[0], cntClass.LabelBuffer.Size);
                    }
                    g.DrawImageUnscaled(cntClass.LabelBuffer, (int)pts[0].X, (int)pts[0].Y);
                }
            }
            finally
            {
                dstHandle.Free();
                srcHandle.Free();
            }
        }
Esempio n. 2
0
        public unsafe void Render(object sender, IDrawArgs drawArgs)
        {
            if (_canvas == null)
            {
                _canvas         = sender as ICanvas;
                _spatialRef     = GetSpatialRef();
                _coordTransfrom = _canvas.CoordTransform;
            }
            Graphics g = drawArgs.Graphics as Graphics;

            if (_gridLines == null)
            {
                bool isOK = ComputeValidGeoRange();
                if (!isOK)
                {
                    return;
                }
                ComputeGridLines(_coordTransfrom);
            }
            if (_gridLines != null)
            {
                GCHandle prjHandle    = GCHandle.Alloc(_allPrjPoints, GCHandleType.Pinned);
                GCHandle screenHandle = GCHandle.Alloc(_allPixelPoints, GCHandleType.Pinned);
                try
                {
                    QuickTransform qickTran = _coordTransfrom.QuickTransform;
                    int            ptCount  = _allPixelPoints.Length;
                    MemoryCopy(screenHandle.AddrOfPinnedObject(), prjHandle.AddrOfPinnedObject(), ptCount * Marshal.SizeOf(typeof(PointF)));
                    fixed(PointF *ptr0 = _allPixelPoints)
                    {
                        PointF *pixPtr = ptr0;

                        for (int i = 0; i < ptCount; i++, pixPtr++)
                        {
                            qickTran.Transform(pixPtr);
                        }
                    }
                    //draw lon lines
                    DrawLines(g, 0, _lonLines);
                    //draw lat lines
                    int end = Math.Min(_lonLines + _latLines, _gridLines.Count);
                    DrawLines(g, _lonLines, end);
                    //label
                    DrawLabel(g, qickTran);
                }
                finally
                {
                    prjHandle.Free();
                    screenHandle.Free();
                }
            }
        }
Esempio n. 3
0
        private void RenderUseDummyMap(RenderArgs args, Bitmap buffer, CoordEnvelope evp)
        {
            double         x1   = evp.MinX;
            double         y1   = evp.MinY;
            double         x2   = evp.MaxX;
            double         y2   = evp.MaxY;
            QuickTransform tran = _canvas.CoordTransform.QuickTransform;

            tran.Transform(ref x1, ref y1);
            tran.Transform(ref x2, ref y2);
            (args.Graphics as Graphics).DrawImage(buffer,
                                                  RectangleF.FromLTRB((float)Math.Min(x1, x2), (float)Math.Min(y1, y2), (float)Math.Max(x1, x2), (float)Math.Max(y1, y2)));
        }
Esempio n. 4
0
        public void Render(object sender, IDrawArgs drawArgs)
        {
            //左上角绘制信息列表
            if (_infoItems.Count == 0)
            {
                return;
            }
            Graphics g        = drawArgs.Graphics as Graphics;
            float    x        = 50;
            float    y        = 10;
            SizeF    fontSize = g.MeasureString("100", _font);
            int      rowStep  = (int)(fontSize.Height + 2);

            foreach (InfoItem item in _infoItems)
            {
                g.DrawString(item.ToString(), _font, Brushes.Yellow, x, y);
                y += rowStep;
            }

            ICanvas canvas = sender as ICanvas;

            if (_visible)
            {
                ICoordinateTransform coordTran = canvas.CoordTransform;
                QuickTransform       qt        = drawArgs.QuickTransformArgs;
                //绘制拐点
                foreach (InfoItem item in _infoItems)
                {
                    int    row = 0, col = 0;
                    double geoX, geoY;
                    coordTran.Geo2Prj(item.Longitude, item.Latitude, out geoX, out geoY);
                    coordTran.Prj2Screen(geoX, geoY, out col, out row);
                    g.FillEllipse(Brushes.Yellow, new RectangleF(col - 3, row - 3, 6, 6));
                }
                //绘制冰缘线
                if (_geoItems != null)
                {
                    foreach (CodeCell.AgileMap.Core.Feature items in _geoItems)
                    {
                        GraphicsPath path = ToGraphicsPath(items, canvas);
                        g.DrawPath(Pens.Red, path);
                    }
                }
            }
        }
Esempio n. 5
0
 public DrawArgsGDIPlus(Graphics graphics, QuickTransform quickTransformArgs)
 {
     _graphics           = graphics;
     _quickTransformArgs = quickTransformArgs;
 }
Esempio n. 6
0
 public DrawArgsGDIPlus(QuickTransform quickTransformArgs)
 {
     _quickTransformArgs = quickTransformArgs;
 }
Esempio n. 7
0
 private void DrawLabel(Graphics g, QuickTransform quickTran)
 {
     if (!_enableLabling)
     {
         return;
     }
     try
     {
         int    idx = 0;
         int    firstLine = -1;
         double geoX, geoY;
         string labelGeoX = string.Empty, labelGeoY = string.Empty;
         PointF pt;
         //label lonlines
         int endLon = Math.Min(_lonLines, _gridLines.Count);
         for (int iLine = 0; iLine < endLon; iLine += _lonLabelStep)
         {
             idx = ComputeLabelLocationOfLon(_gridLines[iLine]);
             if (idx == -1)
             {
                 continue;
             }
             if (firstLine == -1)
             {
                 firstLine = iLine;
             }
             pt   = _allPixelPoints[idx];
             geoX = _allPrjPoints[idx].X;
             geoY = _allPrjPoints[idx].Y;
             _coordTransfrom.Prj2Geo(geoX, geoY, out geoX, out geoY);
             if (double.IsInfinity(geoX) || double.IsNaN(geoX) || double.IsInfinity(geoY) || double.IsNaN(geoY))
             {
                 continue;
             }
             float dlt = 0.005f;
             if (geoX < 0)
             {
                 dlt = -0.005f;
             }
             geoX     += dlt;
             labelGeoX = LabelFormatLon(geoX);
             //避免-180和90重叠
             if (iLine == firstLine)
             {
                 pt.X += _fontSize.Height;
             }
             pt.Y = (20 - _fontSize.Height) / 2;
             if (!_enableMaskColor || _maskBrush == null)
             {
                 g.DrawString(labelGeoX, _labelFont, _labelBrush, pt);
             }
             else
             {
                 DrawStringWithBorder(labelGeoX, g, pt, _labelFont, _labelBrush, _maskBrush);
             }
         }
         //label latlines
         firstLine = -1;
         int begin  = Math.Min(_latLines + _lonLines, _gridLines.Count);
         int endLat = Math.Min(_lonLines, _gridLines.Count);
         for (int iLine = begin - 1; iLine > endLat; iLine -= _latLabelStep)
         {
             idx = ComputeLabelLocationOfLat(_gridLines[iLine]);
             if (idx == -1)
             {
                 continue;
             }
             if (firstLine == -1)
             {
                 firstLine = iLine;
             }
             pt   = _allPixelPoints[idx];
             geoX = _allPrjPoints[idx].X;
             geoY = _allPrjPoints[idx].Y;
             _coordTransfrom.Prj2Geo(geoX, geoY, out geoX, out geoY);
             if (double.IsInfinity(geoX) || double.IsNaN(geoX) || double.IsInfinity(geoY) || double.IsNaN(geoY))
             {
                 continue;
             }
             float dlt = 0.005f;
             if (geoY < 0)
             {
                 dlt = -0.005f;
             }
             geoY     += dlt;
             labelGeoY = LabelFormatLat(geoY);
             //避免90和-180重叠
             if (iLine == firstLine)
             {
                 pt.Y += _fontSize.Height;
             }
             pt.X = (20 - _fontSize.Width) / 2;
             SizeF stringSize = g.MeasureString(labelGeoY, _labelFont);
             g.TranslateTransform(stringSize.Width / 2, stringSize.Height / 2); //设置旋转中心为文字中心
             g.RotateTransform(90f);                                            //旋转
             if (!_enableMaskColor || _maskBrush == null)
             {
                 g.DrawString(labelGeoY, _labelFont, _labelBrush, pt);
             }
             else
             {
                 DrawStringWithBorder(labelGeoY, g, pt, _labelFont, _labelBrush, _maskBrush);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Esempio n. 8
0
        public void Render(object sender, IDrawArgs drawArgs)
        {
            if (!_visible)
            {
                return;
            }
            ICanvas canvas = sender as ICanvas;
            ICoordinateTransform coordTran = canvas.CoordTransform;
            QuickTransform       qt        = drawArgs.QuickTransformArgs;
            Graphics             g         = drawArgs.Graphics as Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;
            Brush blue = new SolidBrush(Color.FromArgb(60, 0, 0, 255));

            Pen bluePen = new Pen(Color.Blue, 2F);
            Pen redPen  = new Pen(Color.Red, 3F);

            redPen.DashStyle = DashStyle.Dot;
            Brush redBrush            = new SolidBrush(Color.Red);
            Brush yelloBrush          = new SolidBrush(Color.Yellow);
            Font  font                = new Font("微软雅黑", 10.0f);
            SizeF distanceFontSize    = g.MeasureString("12111.0", font);
            Brush textBackgroundBrush = new SolidBrush(Color.FromArgb(100, 250, 250, 250));
            Pen   textBackUpPen       = new Pen(Color.FromArgb(125, 125, 125));

            if (_previousParts != null && _previousParts.Count > 0)
            {
                GraphicsPath previous = new GraphicsPath();
                previous.FillMode = FillMode.Winding;
                for (int i = 0; i < _previousParts.Count; i++)
                {
                    List <PointF>     points = new List <PointF>();
                    List <CoordPoint> part   = _previousParts[i];
                    for (int j = 0; j < part.Count; j++)
                    {
                        int col = 0, row = 0;
                        coordTran.Prj2Screen(part[j].X, part[j].Y, out col, out row);
                        points.Add(new PointF(col, row));
                    }
                    g.DrawLines(bluePen, points.ToArray());
                    for (int j = 0; j < points.Count; j++)
                    {
                        g.FillEllipse(yelloBrush, new RectangleF(points[j].X - 3, points[j].Y - 3, 6, 6));
                        if (j == 0)
                        {
                            SizeF textRect = g.MeasureString("起点", font);
                            g.FillRectangle(textBackgroundBrush, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2, textRect.Width, textRect.Height);
                            g.DrawRectangle(textBackUpPen, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2, textRect.Width, textRect.Height);
                            g.DrawString("起点", font, redBrush, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2);
                        }
                        else if (j == _previousDistances[i].Length - 1)
                        {
                            SizeF textRect = g.MeasureString("总长" + FormatDistance(_previousDistances[i][j]), font);
                            g.FillRectangle(textBackgroundBrush, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2, textRect.Width, textRect.Height);
                            g.DrawRectangle(textBackUpPen, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2, textRect.Width, textRect.Height);
                            g.DrawString("总长" + FormatDistance(_previousDistances[i][j]), font, redBrush, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2);
                        }
                        else
                        {
                            SizeF textRect = g.MeasureString(FormatDistance(_previousDistances[i][j]), font);
                            g.FillRectangle(textBackgroundBrush, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2, textRect.Width, textRect.Height);
                            g.DrawRectangle(textBackUpPen, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2, textRect.Width, textRect.Height);
                            g.DrawString(FormatDistance(_previousDistances[i][j]), font, redBrush, points[j].X + 5, points[j].Y - distanceFontSize.Height / 2);
                        }
                    }
                }
            }

            List <PointF> curpoints = new List <PointF>();

            if (_coordinates != null)
            {
                int srceenX = 0, srceenY = 0;
                for (int j = 0; j < _coordinates.Count; j++)
                {
                    coordTran.Prj2Screen(_coordinates[j].X, _coordinates[j].Y, out srceenX, out srceenY);
                    curpoints.Add(new PointF(srceenX, srceenY));
                }
                if (curpoints.Count > 1)
                {
                    g.DrawLines(bluePen, curpoints.ToArray());
                    for (int j = 0; j < curpoints.Count; j++)
                    {
                        PointF pt = curpoints[j];
                        g.FillRectangle(redBrush, new RectangleF(pt.X - 2.5f, pt.Y - 2.5f, 5f, 5f));
                        if (j == 0)
                        {
                            g.DrawString("起点", font, redBrush, pt.X + 5, pt.Y - distanceFontSize.Height / 2);
                        }
                        else
                        {
                            g.DrawString(FormatDistance(_curDistances[j]), font, redBrush, pt.X + 5, pt.Y - distanceFontSize.Height / 2);
                        }
                    }
                }

                if (curpoints.Count > 0 && _mouseDistance > 0)// && _standBy == false && hasMouse)
                {
                    g.DrawLine(redPen, curpoints[curpoints.Count - 1], _mousePosition);
                    SizeF size = g.MeasureString("文字", font);
                    g.DrawString(string.Format("{0}", FormatDistance(_mouseDistance)), font, redBrush, _mousePosition.X + 2, _mousePosition.Y + size.Height);
                    g.DrawString("双击结束", font, redBrush, _mousePosition.X + 2, _mousePosition.Y + size.Height + size.Height);
                    //if (_areaMode && points.Count > 1)
                    //{
                    //    g.DrawLine(redPen, points[0], _mousePosition);
                    //}
                }
                //if (points.Count > 1 && _areaMode && (_previousParts == null || _previousParts.Count == 0))
                //{
                //    if (hasMouse && !_standBy)
                //    {
                //        points.Add(_mousePosition);
                //    }

                //    if (points.Count > 2)
                //    {
                //        g.FillPolygon(blue, points.ToArray());
                //    }
                //}
            }
            bluePen.Dispose();
            redPen.Dispose();
            redBrush.Dispose();
            yelloBrush.Dispose();
            font.Dispose();
            textBackgroundBrush.Dispose();
            textBackUpPen.Dispose();
        }