예제 #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();
            }
        }
예제 #2
0
        public void Draw(Matrix emptyRotateMatrix, Graphics g, LabelDef labelDef, ISymbol currentSymbol, Feature fet, QuickTransformArgs tranArgs)
        {
            string text = fet.GetFieldValue(labelDef.Fieldname);

            if (string.IsNullOrEmpty(text) || labelDef.InvalidValue.Equals(text))
            {
                return;
            }
            Matrix oldMatrix = g.Transform;

            LabelLocation[] locs = GetLabelLocations(fet, labelDef);
            if (locs == null || locs.Length == 0)
            {
                return;
            }
            foreach (LabelLocation loc in locs)
            {
                //标注点在可视区域外
                if (!_environment.ExtentOfProjectionCoord.IsContains(loc.Location))
                {
                    continue;
                }
                //
                pointF.X = (float)(loc.Location.X * tranArgs.kLon + tranArgs.bLon);
                pointF.Y = (float)(loc.Location.Y * tranArgs.kLat + tranArgs.bLat);
                #region debug
                //符号中心点
                //(_environment.ConflictorForLabel as PixelConflictor).DrawTestRectangleF(new PointF(pointF.X - 1, pointF.Y - 1), new SizeF(2, 2), Color.Blue);
                #endregion
                PointF oldPt    = pointF;
                SizeF  fontSize = g.MeasureString(text, labelDef.LabelFont);
                //计算标注矩形区域
                SizeF labelRect = SizeF.Empty;
                if (labelDef.AutoToNewline && text.Length > labelDef.CharcountPerLine)
                {
                    int pos = (int)Math.Ceiling(text.Length / 2f);
                    labelRect         = g.MeasureString(text.Substring(0, pos), labelDef.LabelFont);
                    labelRect.Height *= 2;
                    labelRect.Height  = (float)Math.Ceiling(labelRect.Height);
                }
                else
                {
                    labelRect = g.MeasureString(text, labelDef.LabelFont);
                }
                //应用冲突检测
                masLabelPosition currentpos = labelDef.MasLabelRuler;
                if (_conflictor != null && _conflictor.Enabled)
                {
                    bool   isConflicted = true;
                    PointF originalPt   = pointF;
                    #region debug
                    //if (Array.IndexOf(fet.FieldValues, "东芝笔记本电脑技术服务中心") >= 0 || Array.IndexOf(fet.FieldValues, "甘托克") >= 0)
                    //    Console.WriteLine("");

                    //画出8个候选位置
                    //foreach (masLabelPosition pos in Enum.GetValues(typeof(masLabelPosition)))
                    //{
                    //    switch (pos)
                    //    {
                    //        case masLabelPosition.LeftCenter:
                    //        case masLabelPosition.RightCenter:
                    //        case masLabelPosition.UpCenter:
                    //        case masLabelPosition.BottomCenter:
                    //            pointF = originalPt;
                    //            GetLabelLocation(pos, g, ref  pointF, labelRect, currentSymbol);
                    //            (_environment.ConflictorForLabel as PixelConflictor).DrawTestRectangleF(pointF, labelRect, Color.Blue);
                    //            break;
                    //    }
                    //}
                    #endregion
                    foreach (masLabelPosition pos in Enum.GetValues(typeof(masLabelPosition)))
                    {
                        pointF = originalPt;
                        GetLabelLocation(pos, g, ref pointF, labelRect, currentSymbol);
                        if (!_conflictor.IsConflicted(pointF, labelRect))
                        {
                            isConflicted = false;
                            currentpos   = pos;
                            break;
                        }
                    }
                    if (isConflicted)
                    {
                        return;
                    }
                }
                else
                {
                    //应用对齐方式
                    GetLabelLocation(labelDef.MasLabelRuler, g, ref pointF, fontSize, currentSymbol);
                }
                //
                if (loc.Angle != 0 && loc.Angle != 360)//一般情况下是沿线标注
                {
                    emptyRotateMatrix.Reset();
                    emptyRotateMatrix.RotateAt(loc.Angle, oldPt);
                    g.Transform = emptyRotateMatrix;

                    if (_conflictor != null)
                    {
                        _conflictor.HoldPosition(pointF.X, pointF.Y, labelRect, emptyRotateMatrix);
                    }
                }
                //背景符号
                if (labelDef.ContainerSymbol != null)
                {
                    SizeF backSize = labelDef.ContainerSymbol.Draw(g, pointF, fontSize);
                    if (backSize.Width - fontSize.Width > 0)
                    {
                        pointF.X += (backSize.Width - fontSize.Width) / 2f;
                    }
                    if (backSize.Height - fontSize.Height > 0)
                    {
                        pointF.Y += (backSize.Height - fontSize.Height) / 2f;
                    }
                }
                //写标注
                DrawString(text, g, pointF, labelRect, labelDef);
                //
                if (loc.Angle != 0)
                {
                    g.Transform = oldMatrix;
                }
            }
        }