Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
300
xamWebMap - paths - first path doesn't show up.
posted

Below is about the simplest possible code for drawing a line between two points.  the event is tied to a button that coexists on a page with a xamWebMap.  The map is pretty much drawn from the samples.

The odd thing is that DrawPath_Click does nothing the first time around.  I can see an element added to xamWebMap1.Layers[0].Elements and the visible attribute is set to visible but it doesn't show up on the map.  The second and subsequent calls to DrawPath_Click are fine.

I checked to see if maybe I was one rendering behind all the time and I don't think that's the case but I am often wrong.

private void DrawPath_Click(object sender, RoutedEventArgs e)

{

drawLine(36 + numCalls, -80, 39 + numCalls, -95);

numCalls += 1;

}

void drawLine(double srcLat, double srcLong, double destLat, double destLong)

{

MapPolylineCollection lines = new MapPolylineCollection();

List<Point> points = new List<Point>();

points.Add(new Point(srcLong, srcLat));

points.Add(new Point(destLong, destLat));

lines.Add(xamWebMap1.Projection.ProjectToMap(points));

PathElement lineElement = new PathElement() { Polylines = lines };

lineElement.Fill = new SolidColorBrush(Colors.White);

lineElement.StrokeThickness = 2;

xamWebMap1.Layers[0].Elements.Add(lineElement);

Rect worldRect = lineElement.WorldRect;

worldRect = lines.GetWorldRect();

lineElement.WorldRect = worldRect;

}