Ejemplo n.º 1
0
        /// <summary>
        /// 画注记
        /// </summary>
        /// <param name="g"></param>
        /// <param name="bounds"></param>
        /// <param name="centerPos"></param>
        /// <param name="scale"></param>
        /// <param name="fid2Text"></param>
        internal override void DrawLabel(Graphics g, Rectangle bounds, PointF centerPos, double scale, Dictionary <int, string> fid2Text, TextSymbol textSymbol)
        {
            MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y));
            double  xmin     = xyCenter.X - scale * bounds.Width / 2;
            double  xmax     = xyCenter.X + scale * bounds.Width / 2;
            double  ymin     = xyCenter.Y - scale * bounds.Height / 2;
            double  ymax     = xyCenter.Y + scale * bounds.Height / 2;

            for (int i = 0; i < polygons.Count; i++)
            {
                List <PointF> pointfs = new List <PointF>();
                for (int j = 0; j < polygons[i].PointCount; j++)
                {
                    MyPoint xyProjection = ETCProjection.LngLat2XY(polygons[i].Points[j]);
                    double  xScreen      = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin);
                    double  yScreen      = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin);
                    PointF  p            = new PointF((float)xScreen, bounds.Height - (float)yScreen);
                    pointfs.Add(p);
                }
                RectangleF mbr  = GeometryTools.GetMBR(pointfs.ToArray());
                string     text = fid2Text[polygons[i].FID];
                if (Math.Max(mbr.Width, mbr.Height) > textSymbol.TextStyle.TextSize * text.Length)
                {
                    TextSymbol.PolygonLabel(pointfs.ToArray(), g, textSymbol, text);
                }
            }
        }