Пример #1
0
        private void RenderFeatures(Graphics g, QuickTransformArgs quickTransfrom)
        {
            IFeatureClass fetclass = _class as IFeatureClass;

            IGrid[] grids = fetclass.Grids;
            if (grids == null || grids.Length == 0)
            {
                return;
            }
            try
            {
                fetclass.RepeatFeatureRecorder.BeginRender();
                int               gridCount        = grids.Length;
                Envelope          currentExtent    = _environment.ExtentOfProjectionCoord;
                Grid              gd               = null;
                IOutsideIndicator outsideIndicator = null;
                //
                for (int i = 0; i < gridCount; i++)
                {
                    gd = grids[i] as Grid;
                    if (gd.IsEmpty())
                    {
                        continue;
                    }
                    outsideIndicator = (gd as ISupportOutsideIndicator).OutsideIndicator;
                    //test,draw grids
                    //DrawTestGrid(gd, g, quickTransfrom);
                    //

                    /* 为了测试其他投影矢量绘制注释掉
                     * outsideIndicator.SetOutside(!currentExtent.IsInteractived(gd.GridEnvelope,ref gd._isfullInternal));
                     * if (outsideIndicator.IsOutside)
                     *  continue;
                     */
                    outsideIndicator.SetOutside(!currentExtent.IsInteractived(gd.GridEnvelope, ref gd._isfullInternal));
                    if (outsideIndicator.IsOutside)
                    {
                        continue;
                    }
                    _featureRender.Render(_enabledDisplayLevel, quickTransfrom, gd, g, currentExtent, fetclass.RepeatFeatureRecorder);
                }
            }
            finally
            {
                fetclass.RepeatFeatureRecorder.EndRender();
            }
        }
Пример #2
0
        //private void ComputeQuickArgs_OLD()
        //{
        //    if (_quickTransfrom == null)
        //    {
        //        _quickTransfrom = new QuickTransformArgs();
        //        ShapePoint geoPt1 = new ShapePoint(70, 0);
        //        ShapePoint geoPt2 = new ShapePoint(140, 70);
        //        ShapePoint[] geoPts = new ShapePoint[] { geoPt1, geoPt2 };
        //        GeoCoord2PrjCoord(geoPts);
        //        //
        //        prjPt1ForQuickArgs = geoPts[0].ToPointF();
        //        prjPt2ForQuickArgs = geoPts[1].ToPointF();
        //        screenPtsForQuickArgs = new PointF[2];
        //        prjDlatXForQuickArgs = 1f / (prjPt1ForQuickArgs.X - prjPt2ForQuickArgs.X);
        //        prjDlatYForQuickArgs = 1f / (prjPt1ForQuickArgs.Y - prjPt2ForQuickArgs.Y);
        //    }
        //    //Stopwatch sw = new Stopwatch();
        //    //sw.Start();
        //    //
        //    screenPtsForQuickArgs[0] = prjPt1ForQuickArgs;
        //    screenPtsForQuickArgs[1] = prjPt2ForQuickArgs;
        //    PrjCoord2PixelCoord(screenPtsForQuickArgs);
        //    //
        //    _quickTransfrom.kLon = (screenPtsForQuickArgs[0].X - screenPtsForQuickArgs[1].X) * prjDlatXForQuickArgs; //(screenPts[0].X - screenPts[1].X) / (prjPt1.X - prjPt2.X);
        //    _quickTransfrom.kLat = (screenPtsForQuickArgs[0].Y - screenPtsForQuickArgs[1].Y) * prjDlatYForQuickArgs; //(screenPts[0].Y - screenPts[1].Y) / (prjPt1.Y - prjPt2.Y);
        //    _quickTransfrom.bLon = screenPtsForQuickArgs[0].X - _quickTransfrom.kLon * prjPt1ForQuickArgs.X;
        //    _quickTransfrom.bLat = screenPtsForQuickArgs[0].Y - _quickTransfrom.kLat * prjPt1ForQuickArgs.Y;
        //    //sw.Stop();
        //    //long losttimes = sw.ElapsedTicks;
        //}

        private void ComputeQuickArgs()
        {
            if (_quickTransfrom == null)
            {
                _quickTransfrom = new QuickTransformArgs();
            }
            screenPtsForQuickArgs[0] = new Point(0, 0);
            screenPtsForQuickArgs[1] = new Point(this.Host.CanvasSize.Width, this.Host.CanvasSize.Height);
            prjPt1ForQuickArgs[0]    = screenPtsForQuickArgs[0];
            prjPt1ForQuickArgs[1]    = screenPtsForQuickArgs[1];
            this.PixelCoord2PrjCoord(prjPt1ForQuickArgs);
            prjDlatXForQuickArgs = 1f / (prjPt1ForQuickArgs[0].X - prjPt1ForQuickArgs[1].X);
            prjDlatYForQuickArgs = 1f / (prjPt1ForQuickArgs[0].Y - prjPt1ForQuickArgs[1].Y);
            _quickTransfrom.kLon = (screenPtsForQuickArgs[0].X - screenPtsForQuickArgs[1].X) * prjDlatXForQuickArgs; //(screenPts[0].X - screenPts[1].X) / (prjPt1.X - prjPt2.X);
            _quickTransfrom.kLat = (screenPtsForQuickArgs[0].Y - screenPtsForQuickArgs[1].Y) * prjDlatYForQuickArgs; //(screenPts[0].Y - screenPts[1].Y) / (prjPt1.Y - prjPt2.Y);
            _quickTransfrom.bLon = screenPtsForQuickArgs[0].X - _quickTransfrom.kLon * prjPt1ForQuickArgs[0].X;
            _quickTransfrom.bLat = screenPtsForQuickArgs[0].Y - _quickTransfrom.kLat * prjPt1ForQuickArgs[0].Y;
        }
Пример #3
0
        private void DrawTestGrid(IGrid gd, Graphics g, QuickTransformArgs quickTransform)
        {
            Envelope evp = gd.GridEnvelope.Clone() as Envelope;

            ShapePoint[] pts   = evp.Points;
            PointF[]     ptfs  = new PointF[pts.Length];
            int          ptIdx = 0;

            foreach (ShapePoint pt in pts)
            {
                pt.X          = pt.X * quickTransform.kLon + quickTransform.bLon;
                pt.Y          = pt.Y * quickTransform.kLat + quickTransform.bLat;
                ptfs[ptIdx].X = (float)pt.X;
                ptfs[ptIdx].Y = (float)pt.Y;
                ptIdx++;
            }
            g.DrawPolygon(Pens.Red, ptfs);
            g.DrawString(gd.GridNo.ToString(), new Font("宋体", 9), Brushes.Red, new PointF(ptfs[0].X + 6, ptfs[0].Y + 6));
        }
Пример #4
0
        private void ComputeQuickArgs(Matrix transform)
        {
            if (_quickTranArgs == null)
            {
                _quickTranArgs = new QuickTransformArgs();
            }
            ShapePoint geoPt1 = _features[0].Geometry.Centroid;
            ShapePoint geoPt2 = _features[_features.Count - 1].Geometry.Centroid;
            PointF     prjPt1 = geoPt1.ToPointF();
            PointF     prjPt2 = geoPt2.ToPointF();

            PointF[] screenPts = new PointF[] { prjPt1, prjPt2 };
            transform.TransformPoints(screenPts);
            //
            _quickTranArgs.kLon = (screenPts[0].X - screenPts[1].X) / (prjPt1.X - prjPt2.X);
            _quickTranArgs.kLat = (screenPts[0].Y - screenPts[1].Y) / (prjPt1.Y - prjPt2.Y);
            _quickTranArgs.bLon = screenPts[0].X - _quickTranArgs.kLon * prjPt1.X;
            _quickTranArgs.bLat = screenPts[0].Y - _quickTranArgs.kLat * prjPt1.Y;
        }
Пример #5
0
        public void Render(System.Drawing.Graphics g, QuickTransformArgs quickTransform)
        {
            Envelope currentExtent = _environment.ExtentOfProjectionCoord;

            if (!currentExtent.IsInteractived(_class.FullEnvelope))
            {
                return;
            }
            IMapRuntime        runtime   = _environment as IMapRuntime;
            IRasterDataSource  ds        = _class.DataSource as IRasterDataSource;
            enumCoordinateType coordType = ds.GetCoordinateType();
            Envelope           evp       = null;

            if (coordType == enumCoordinateType.Geographic)
            {
                evp = ToGeoEnvelope(runtime, currentExtent);
            }
            Bitmap bm = ds.Reader.Read(evp, runtime.Host.CanvasSize.Width, runtime.Host.CanvasSize.Height);

            if (bm != null)
            {
                g.DrawImage(bm, 0, 0);
            }
        }
Пример #6
0
 public void Render(Graphics g, QuickTransformArgs quickTransfrom)
 {
     RenderFeatures(g, quickTransfrom);
 }
Пример #7
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;
                }
            }
        }
Пример #8
0
        public void Render(bool enableDisplayLevel, QuickTransformArgs quickTransformArgs, IGrid gd, Graphics g, Envelope rect, RepeatFeatureRecorder recorder)
        {
            if (g == null)
            {
                return;
            }
            _currentFeatureRects.Clear();
            List <Feature> features = gd.VectorFeatures;

            if (features == null || features.Count == 0)
            {
                return;
            }
            _quickTransformArgs = quickTransformArgs;
            int               fetCount         = features.Count;
            Feature           feature          = null;
            IOutsideIndicator outsideIndicator = null;
            bool              isfullInside     = (gd as Grid)._isfullInternal;

            for (int i = 0; i < fetCount; i++)
            {
                feature = features[i];
                if (feature == null || feature.Geometry == null)
                {
                    continue;
                }
                outsideIndicator = feature.OutsideIndicator;// (feature as ISupportOutsideIndicator).OutsideIndicator;
                //判断是否在该级别显示
                if (enableDisplayLevel && feature.DisplayLevel != -1)
                {
                    if (feature.DisplayLevel > _environment.CurrentLevel)
                    {
                        outsideIndicator.SetOutside(true);
                        continue;
                    }
                }
                //可见性计算
                if (!isfullInside)
                {
                    if (feature.Geometry is ShapePoint)
                    {
                        outsideIndicator.SetOutside(!IsPointInCurrentExtent(feature, rect));
                    }
                    else //Polyline,Polygon
                    {
                        outsideIndicator.SetOutside(!IsPolygonInCurrentExtent(feature, rect));
                    }
                    if (outsideIndicator.IsOutside)
                    {
                        continue;
                    }
                }
                else//整个网格都在可视区域内部
                {
                    outsideIndicator.SetOutside(false);
                }
                //是否已经在其他网格绘制过了
                if (feature.IsRepeatedOverGrids)
                {
                    if (recorder.IsRendered(feature.OID))
                    {
                        continue;
                    }
                    else
                    {
                        recorder.AddRenderedOID(feature.OID);
                    }
                }
                //为要素设置绘制符号
                SetCurrentSymbolFromFeature(feature);
                if (_currentSymbol == null)
                {
                    continue;
                }
                //为符号设置角度
                SetAngleOfSymbol(feature);
                //画几何形状
                try
                {
                    if (feature.Geometry is ShapePoint)
                    {
                        PointF pt = ShapePoint2PixelPoint(feature.Geometry as ShapePoint);
                        //位置冲突检测
                        if (_environment != null)
                        {
                            IConflictor conflictorForSymbol = _environment.ConflictorForSymbol;
                            if (conflictorForSymbol != null && conflictorForSymbol.Enabled)
                            {
                                //符号冲突
                                if (conflictorForSymbol.IsConflicted(pt.X - _currentSymbol.SymbolHalfWidth,
                                                                     pt.Y - _currentSymbol.SymbolHalfHeight,
                                                                     _currentSymbol.SymbolSize))
                                {
                                    outsideIndicator.SetOutside(true);
                                    continue;
                                }
                            }
                        }
                        //画符号
                        DrawPointUseCurrentSymbol(g, pt);
                        //记下要素符号矩形区域
                        _currentFeatureRects.Add(feature, new RectangleF((_currentSymbol as IMarkerSymbol).PixelLocation, _currentSymbol.SymbolSize));
                        //符号不冲突,在标注冲突检测网格中占位
                        #region debug
                        //符号矩形
                        //PointF tpt = new PointF((pt.X - _currentSymbol.SymbolSize.Width / 2f),
                        //                                      (pt.Y - _currentSymbol.SymbolSize.Height / 2f));
                        //(_environment.ConflictorForLabel as PixelConflictor).DrawTestRectangleF(tpt, _currentSymbol.SymbolSize, Color.Yellow);
                        #endregion
                        if (_environment != null)
                        {
                            if (_environment.ConflictorForLabel != null && _environment.ConflictorForLabel.Enabled)
                            {
                                _environment.ConflictorForLabel.HoldPosition((pt.X - _currentSymbol.SymbolSize.Width / 2f),
                                                                             (pt.Y - _currentSymbol.SymbolSize.Height / 2f),
                                                                             _currentSymbol.SymbolSize);
                            }
                        }
                    }
                    else //Polyline,Polygon
                    {
                        SetGraphicsPathFromGeometry(feature.Geometry);
                        if (_path.PointCount > 0)
                        {
                            DrawPathUseCurrentSymbol(g);
                            _currentFeatureRects.Add(feature, RectangleF.Empty);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.WriterException("BaseFeatureRenderer", "Render(Layer:" + (_name != null ?_name : string.Empty) + ",OID:" + feature.OID.ToString() + ")", ex);
                }
                finally
                {
                    _currentSymbol.Angle = 0;
                }
            }
        }