Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top