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;

}

Parents
No Data
Reply
  • 28496
    Offline posted

    this worked fine for me using your code on a page like this:

    <Grid x:Name="LayoutRoot">
            <igMap:XamWebMap x:Name="xamWebMap1">
                <igMap:XamWebMap.Layers>
                    <igMap:MapLayer>
                        <igMap:MapLayer.Reader>
                            <igMap:ShapeFileReader Uri="world" />
                        </igMap:MapLayer.Reader>
                    </igMap:MapLayer>
                </igMap:XamWebMap.Layers>
            </igMap:XamWebMap>
            <Button Height="50" Width="50" x:Name="DrawPath" Click="DrawPath_Click" />
        </Grid>

    the first time i clicked the button, a white line was drawn from South Carolina to the Mississippi river.  i tested this using version 9.1.20091.1000.  what version are you using?

    is the map fully loaded and rendered when you click this button?

    as a workaround, you could try calling MapLayer.RenderWindow() to force a re-render.  beware, though, this causes a full refresh of the map which is an unnecessarily large operation and could impact your application's performance.

Children