我正在使用 MapLayer 和 MapOverlay 在地图中创建自己的路径/折线,GPS 捕获的所有点都存储在一个结构中,以便我可以访问它们。任何时候。
现在,我希望在用户操作地图的同时变换路径(缩放和地图重新定位),因此路径仍然连接相同的点。到目前为止,我的方法非常消耗 CPU,而且看起来很糟糕
GeocoordinateList _coordinates;
MapLayer pointsLayer;
private void MyMap_ZoomLevelChanged(object sender, MapZoomLevelChangedEventArgs e)
{
repositionPoints(); // This is done other way but for the sake of brevity
}
private void repositionPathPoints()
{
try
{
Polyline path = (Polyline)pointsLayer.First(TrackPath).Content; // retrieves MapOverlay corresponding to line
path.Points.Clear();
path.Points = new PointCollection();
foreach (Geocoordinate coord in _coordinates)
{
path.Points.Add(MyMap.ConvertGeoCoordinateToViewportPoint(coord));
}
}
catch (Exception exc)
{
Debug.WriteLine(exc.Message);
}
}
有没有更有效的方法使用 XAML 方法来做到这一点?我发现了这个关于如何缩放地图的旧线程,但在我的情况下,地图存储的缩放级别只是一个从 1 到 20 的数值,没有指示每次缩放跳跃的比例百分比。