none
Problem with polyline - not drawing correctly, location points around the earth RRS feed

  • Question

  • Ok first of all I'm trying to port my app from Windows Phone 8 and in the app I have a map control and I'm drawing a poly line all around the earth from -180 to 180 at 10 degree intervals of longitude. The poly line shows up perfect in WIndows Phone and draws as expected, zoomed in or out. It gets drawn all around the earth on the map.

    On to WIndows Store and I'm using this method to draw the same points, but when I zoom out to see the entire map it only show the points from HALF of the earth, not all at once like it does in Windows Phone. Plus its connecting the end points together to form a straight line between them. And when I scroll side to side, the poly line jumps into the current half i'm in, leaving no line on the other half.

    The fact is when you are zoomed out, you should see the line at the geographic position even if that position occurs twice in the view.  Like if you're zoomed out so much that there are two instances of North American continent in view, the line should show up on both, but it is not.

    This is the code I'm using

                MapShapeLayer shapeLayer = new MapShapeLayer();
                MapPolyline polyline = new MapPolyline();
                LocationCollection lc = new LocationCollection();
                foreach (Geopoint g in a.GeographicPoints)
                    lc.Add(new Location(g.Position.Latitude, g.Position.Longitude));
    
                polyline.Locations = lc;
    
                polyline.Color = Windows.UI.Colors.Red;
                polyline.Width = 5;
                shapeLayer.Shapes.Add(polyline);
                myMap.ShapeLayers.Add(shapeLayer);




    • Edited by Sal_S Thursday, April 24, 2014 3:14 AM
    Thursday, April 24, 2014 3:08 AM

Answers

  • That's exactly what I get as well. That's the expected experience as the line is staying on one world and is moving the world that overlaps with the center of the map view. The only way to modify this is to only show one map instead of having the world wrap. You can do this using the map restriction setting on the map: http://msdn.microsoft.com/en-us/library/jj620948.aspx

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Thursday, April 24, 2014 1:35 PM
    • Marked as answer by Sal_S Friday, April 25, 2014 2:31 AM
    Thursday, April 24, 2014 1:35 PM
  • Shapes on the map are individual UIElements, just like a user control. Adding more than one instance of them to the map would cause an error, just like trying to add an existing control to a grid would. This is why there is only one shape shown on the map. All that said I'm unable to reproduce the issue you are reporting. When more than one map is visible the map that intersects the center of the map is used as the primary map for rendering. The only time I can get close to what you are commenting on is when I'm zoomed into one of the end points and the line is split between the two different maps. Here is the code I used to test:

    MyMap.Loaded += (s, e) =>
    {
        var locs = new LocationCollection();
                    
        for (int i = -180; i <= 180; i += 10)
        {
            locs.Add(new Location(50, i));
        }
    
        var poly = new MapPolyline(){
            Locations = locs,
            Color = Colors.Red,
            Width = 5
        };
    
        var layer = new MapShapeLayer();
        MyMap.ShapeLayers.Add(layer);
    
        layer.Shapes.Add(poly);
    };
    One option to get rid of this experience is to only show one map instead of having the world wrap. You can do this using the map restriction setting on the map: http://msdn.microsoft.com/en-us/library/jj620948.aspx


    http://rbrundritt.wordpress.com

    Thursday, April 24, 2014 10:38 AM
  • Thank you, mapViewRestriction setting worked. But the other problem still persists, and that is when I drawl the points from 180 to -180 all the way around the earth, the end point get joined together by a straight line.  You can't notice it if you keep the latitude a constant,  You have to curve the points and then you will see it.

    Try it with these point and you will see, as soon as the line crosses the edge of the map, it creates a straight line across the whole map.

    LAT, LON

    61,171

    60,-177

    53,-167

    57,-157

    55,-148

    seems that it matters what order you draw the polyline points.  I have to sort them in ascending order from -180 to 180 and that fixed the issue.


    List<Geopoint> glist = MapPoints.OrderBy(x => x.Position.Longitude).ToList();

    • Edited by Sal_S Friday, April 25, 2014 2:31 AM
    • Marked as answer by Sal_S Friday, April 25, 2014 2:31 AM
    Friday, April 25, 2014 2:30 AM

All replies

  • Shapes on the map are individual UIElements, just like a user control. Adding more than one instance of them to the map would cause an error, just like trying to add an existing control to a grid would. This is why there is only one shape shown on the map. All that said I'm unable to reproduce the issue you are reporting. When more than one map is visible the map that intersects the center of the map is used as the primary map for rendering. The only time I can get close to what you are commenting on is when I'm zoomed into one of the end points and the line is split between the two different maps. Here is the code I used to test:

    MyMap.Loaded += (s, e) =>
    {
        var locs = new LocationCollection();
                    
        for (int i = -180; i <= 180; i += 10)
        {
            locs.Add(new Location(50, i));
        }
    
        var poly = new MapPolyline(){
            Locations = locs,
            Color = Colors.Red,
            Width = 5
        };
    
        var layer = new MapShapeLayer();
        MyMap.ShapeLayers.Add(layer);
    
        layer.Shapes.Add(poly);
    };
    One option to get rid of this experience is to only show one map instead of having the world wrap. You can do this using the map restriction setting on the map: http://msdn.microsoft.com/en-us/library/jj620948.aspx


    http://rbrundritt.wordpress.com

    Thursday, April 24, 2014 10:38 AM
  • I tried even with your code and I get the same effect.

    Watch this video to see a demonstration of how the polyline jumps into view when you drag the map from right to left.

    https://onedrive.live.com/redir?resid=E1D785993673947E!74850&authkey=!AGKdLMjjYvlzMSw&ithint=video%2c.mp4

    Thursday, April 24, 2014 12:33 PM
  • That's exactly what I get as well. That's the expected experience as the line is staying on one world and is moving the world that overlaps with the center of the map view. The only way to modify this is to only show one map instead of having the world wrap. You can do this using the map restriction setting on the map: http://msdn.microsoft.com/en-us/library/jj620948.aspx

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Thursday, April 24, 2014 1:35 PM
    • Marked as answer by Sal_S Friday, April 25, 2014 2:31 AM
    Thursday, April 24, 2014 1:35 PM
  • Thank you, mapViewRestriction setting worked. But the other problem still persists, and that is when I drawl the points from 180 to -180 all the way around the earth, the end point get joined together by a straight line.  You can't notice it if you keep the latitude a constant,  You have to curve the points and then you will see it.

    Try it with these point and you will see, as soon as the line crosses the edge of the map, it creates a straight line across the whole map.

    LAT, LON

    61,171

    60,-177

    53,-167

    57,-157

    55,-148

    • Edited by Sal_S Friday, April 25, 2014 2:04 AM
    Friday, April 25, 2014 1:40 AM
  • Thank you, mapViewRestriction setting worked. But the other problem still persists, and that is when I drawl the points from 180 to -180 all the way around the earth, the end point get joined together by a straight line.  You can't notice it if you keep the latitude a constant,  You have to curve the points and then you will see it.

    Try it with these point and you will see, as soon as the line crosses the edge of the map, it creates a straight line across the whole map.

    LAT, LON

    61,171

    60,-177

    53,-167

    57,-157

    55,-148

    seems that it matters what order you draw the polyline points.  I have to sort them in ascending order from -180 to 180 and that fixed the issue.


    List<Geopoint> glist = MapPoints.OrderBy(x => x.Position.Longitude).ToList();

    • Edited by Sal_S Friday, April 25, 2014 2:31 AM
    • Marked as answer by Sal_S Friday, April 25, 2014 2:31 AM
    Friday, April 25, 2014 2:30 AM