【问题标题】:Drawing arrows on bing maps in Silverlight在 Silverlight 中的 bing 地图上绘制箭头
【发布时间】:2010-09-24 09:15:16
【问题描述】:

我需要画线来展示 Bing 地图上的货物运输。为了阐明起点和终点,我在目的地一侧画了一个小箭头。问题是,当我查看全球地图时,某些线会沿着“绕后”的最短路径绘制。例如,从纽约市到东京,它将跨越太平洋。由于箭头是单独绘制的,所以它是相反的。

>------- 

而不是

<-------

当用户在地图上向东/向西滚动时,这个问题会变得更糟,因此欧洲不再居中。

这是我到目前为止的代码。我没有写这个,但仍然必须修复这个问题中出现的错误。如果您有优化建议,请随时提出。

public class MapArrow
{
    private readonly MapPolyline line;
    private readonly MapLayer arrowLayer;
    private readonly Polyline arrowLine;

    #region constructor

    public MapArrow(Location start, Location end)
        : this(start, end, Colors.Red)
    {

    }

    public MapArrow(Location start, Location end)
    {
        color.A = 200;
        Color = Colors.Red;
        drawingColor = Colors.Red;
        HeadWidth = 8;
        HeadHeight = 8;
        StrokeThikness = 5;
        Start = start;
        End = end;

        line = new MapPolyline();
        arrowLayer = new MapLayer();
        arrowLine = new Polyline();
        arrowLayer.AddChild(arrowLine, end);
        UpdateMapLine();
        UpdateArrowPolyline();
    }

    #endregion

    #region properties

    public double HeadWidth { get; set; }

    public double HeadHeight { get; set; }

    public Color Color { get; set; }

    public int StrokeThikness { get; set; }

    public Location Start { get; private set; }

    public Location End { get; private set; }

    public MapPolyline Line
    {
        get
        {
            return line;
        }
    }
    public MapLayer Arrow
    {
        get
        {
            return arrowLayer;
        }
    }

    #endregion

    private void UpdateMapLine()
    {
        line.Stroke = new SolidColorBrush(drawingColor);
        line.StrokeThickness = StrokeThikness;
        line.Opacity = 1;
        line.Locations = new LocationCollection() 
        {
            Start,
            End
        };
    }

    private void UpdateArrowPolyline()
    {
        double theta = Math.Atan2(Start.Latitude - End.Latitude, Start.Longitude - End.Longitude);
        double sint = Math.Sin(theta);
        double cost = Math.Cos(theta);

        Point corner1;
        Point corner2;
        if (!Start.Equals(End))
        {
            corner1 = new Point(
                (HeadWidth*cost - HeadHeight*sint),
                0 - (HeadWidth*sint + HeadHeight*cost));

            corner2 = new Point(
                (HeadWidth*cost + HeadHeight*sint),
                (HeadHeight*cost - HeadWidth*sint));
        }
        else
        {
            corner1 = new Point(0,StrokeThikness/2);
            corner2 = new Point(0,-StrokeThikness/2);
        }

        Point endPoint = new Point(0, 0);

        arrowLine.Stroke = new SolidColorBrush(drawingColor);
        arrowLine.StrokeThickness = StrokeThikness;
        arrowLine.Opacity = 1;

        arrowLine.Points = new PointCollection() 
        {
            corner1,
            endPoint,
            corner2
        };
    }
}

【问题讨论】:

    标签: silverlight drawing bing-maps


    【解决方案1】:

    最短的(大圆)是正确的画法。放大到 2d 投影时它会发生变化吗?

    您能否检测出正在显示的视图并据此更改方向?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 2020-03-07
      相关资源
      最近更新 更多