Exemple #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);
            }
        }
Exemple #2
0
 private PointD rotate(PointD v, float r)
 {
     double c = (double)Math.Cos(r), s = (double)Math.Sin(r);
     return new PointD(v.x * c - v.y * s, v.x * s + v.y * c);
 }