Transform Path/Polyline corresponding to Map zoom/move action

隐身守侯 提交于 2019-12-10 21:40:59

问题


I'm creating my own path/polyline in a Map using a MapLayer and a MapOverlay, all the points captured by the GPS are stored in a structure so I can access them. Anytime.

Now, I want the path to transform at the same time the Map is manipulated by the user (zoom and map reposition) so the path is still joining the same points. So far my method is very CPU hungry and looks terrible

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);
        }
}

Is there any more efficient way of doing this using XAML methods? I found this old thread about how to scale a map but in my case the zoom level stored by the map is just a numeric value from 1 to 20 with no indication of scale % per zoom jump.


回答1:


I solved this by going through the documentation. What I really needed was a MapPolyline that was already provided by the SDK, with methods accepting Geocoordinates instead of points. You just need to add them as MapElements or child of a MapLayer.



来源:https://stackoverflow.com/questions/13607184/transform-path-polyline-corresponding-to-map-zoom-move-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!