Пример #1
0
        public Tile plot(Label label, TextBlock labelTB, Canvas canvas, Image img, RotateTransform trans)
        {
            this.labelTextBlock = labelTB;
            this.bitmap = canvas;
            this.labelIcon = img;
            this.labelTrans = trans;

            iustc.map.data.Rect bounds = getLabelBounds(label);
            int labelWidth = (int)Math.Abs(bounds.right - bounds.left);
            int labelHeight = (int)Math.Abs(bounds.bottom - bounds.top);
            PointD[] points = new PointD[]{
                rotate(new PointD(0, labelHeight), label.orient),
                rotate(new PointD(labelWidth, 0), label.orient),
                rotate(new PointD(labelWidth, labelHeight), label.orient)};

            bounds = new iustc.map.data.Rect(0, labelHeight, 0, labelHeight);
            foreach (PointD p in points)
            {
                int x = (int)Math.Round(p.x);
                int y = labelHeight - (int)Math.Round(p.y);
                bounds.left = Math.Min(bounds.left, x);
                bounds.right = Math.Max(bounds.right, x);
                bounds.top = Math.Min(bounds.top, y);
                bounds.bottom = Math.Max(bounds.bottom, y);
            }

            int width = Math.Max(1, Math.Abs(bounds.right - bounds.left));
            int height = Math.Max(1, Math.Abs(bounds.bottom - bounds.top));

            if (isRoadType(label.type))
            {
                PointD p1 = rotate(new PointD(0, labelHeight / 2), label.orient);
                PointD p2 = rotate(new PointD(labelWidth, labelHeight / 2), label.orient);

                int x1 = (int)Math.Round(p1.x) - bounds.left;
                int y1 = labelHeight - (int)Math.Round(p1.y) - bounds.top;
                int x2 = (int)Math.Round(p2.x) - bounds.left;
                int y2 = labelHeight - (int)Math.Round(p2.y) - bounds.top;

                labelTextBlock.Text = label.text;
                labelTextBlock.Foreground = PlotterHelper.ROAD_TEXT_COLOR;
                labelTextBlock.RenderTransformOrigin = new Point(0.5, 0.5);
                labelTrans.Angle = -label.orient;
                labelTextBlock.RenderTransform = labelTrans;

                bitmap.Children.Add(labelTextBlock);
                return new Tile(label.lat, label.lon, bitmap, (x1+x2)/2, (y1+y2)/2);
            }
            else
            {
                PointD p1 = rotate(new PointD(0, labelHeight / 2), label.orient);
                PointD p2 = rotate(new PointD(labelWidth, labelHeight / 2), label.orient);

                int x1 = (int)Math.Round(p1.x) - bounds.left;
                int y1 = labelHeight - (int)Math.Round(p1.y) - bounds.top;
                int x2 = (int)Math.Round(p2.x) - bounds.left;
                int y2 = labelHeight - (int)Math.Round(p2.y) - bounds.top;

                labelTextBlock.Text = label.text;
                labelTextBlock.Foreground = PlotterHelper.POI_TEXT_COLOR;
                labelTextBlock.RenderTransformOrigin = new Point(0.5, 0.5);
                labelTrans.Angle = -label.orient;
                labelTextBlock.RenderTransform = labelTrans;

                BitmapImage iconOfRoad = getLabelIcon(label);
                labelIcon.Source = iconOfRoad;
                bitmap.Children.Add(this.labelIcon);
                bitmap.Children.Add(labelTextBlock);
                labelIcon.SetValue(Canvas.TopProperty, 10.0);
                labelTextBlock.SetValue(Canvas.LeftProperty, 10.0);
                return new Tile(label.lat, label.lon, bitmap, (x1+x2)/2, (y1+y2)/2);
            }
        }
Пример #2
0
        private iustc.map.data.Rect getLabelBounds(Label label)
        {
            iustc.map.data.Rect rect = new iustc.map.data.Rect();

            if (label.text.Length == 0)
                return rect;

            //            TextBlock tmpTextBlock = new TextBlock();
            //            tmpTextBlock.Text = label.text;

            if (isRoadType(label.type))
            {
                //roadTextBorderPaint.getTextBounds(label.text, 0, label.text.length(), rect);
                rect.top = 0;
                rect.left = 0;
                rect.right = (int)Math.Round(labelTextBlock.Width);
                rect.bottom = (int)Math.Round(labelTextBlock.Height);
                rect.bottom += 4;
            }
            else
            {
                //poiTextBorderPaint.getTextBounds
                rect.top = 0;
                rect.left = 0;
                rect.right = (int)Math.Round(labelTextBlock.ActualWidth);
                rect.bottom = (int)Math.Round(labelTextBlock.ActualHeight);
                rect.bottom += 4;

                BitmapImage icon = getLabelIcon(label);
                if (icon != null)
                {
                    if (rect.height < icon.PixelHeight)
                    {
                        rect.bottom += icon.PixelHeight - rect.height;
                    }
                    rect.bottom += icon.PixelWidth + 4;
                }
            }
            return rect;
        }