Drawing Polygon With Mouse

Jul 26, 2011 at 8:04 PM
Edited Jul 26, 2011 at 8:25 PM

I'm attempting to add lines on the map and I'm some problems. The line points are defined by mouse clicks, but there seems to be something off about the way I'm getting them or the way I'm adding the lines to the graph because they always seem to end up in a circle around the North Pole.

For the sake of simplicity, I have taken out the mouse click events and hard coded the latitude and longitude values in the following code to demonstrate what I'm doing.

PolyInfo polyLineInfo = PolyInfo.DefaultPolygon;
List<LatLonAlt> points = new List<LatLonAlt>
{
    new LatLonAlt(49.1388975547463, -126.075587370943, 0),
    new LatLonAlt(48.9432711597754, -120.613371775982, 0),
    new LatLonAlt(48.0001594130985, -120.97845550016, 0),
    new LatLonAlt(47.6910468965152, -124.603996820548, 0),
    new LatLonAlt(48.941077583781, -126.206758003189, 0)
};

polyLineInfo.AltitudeMode = AltitudeMode.FromGround;
polyLineInfo.LineColor = System.Drawing.Color.Yellow;
polyLineInfo.LineWidth = 15;

GlobeControl.Host.Geometry.AddGeometry(new
    PolylineGeometry("route", "route", null, points.ToArray(),
    PolylineGeometry.PolylineFormat.Polyline2D, polyLineInfo));

 

The points in the list were obtained from the following:

VELatLong point = VEPointToLatLong(e.GetPosition(this));
The following screenshot demonstrates the affect I'm obtaining from the above code: http://imgur.com/VP5zf
When everything is all said and done, I'll take all of the points and generate a true polygon (where the start point and end point are the same), but since it starts out with open-ended lines, I'm still trying to get that part working.
Jul 27, 2011 at 7:48 PM

I just wanted to point out, the code below causes the same circle to be drawn across the north pole, despite the coordinates being the four "corners" (for lack of better words) of the continental US:

PolyInfo polyLineInfo = PolyInfo.DefaultPolygon;
List<LatLonAlt> points = new List<LatLonAlt>
    {
        new LatLonAlt(48.4583518, -123.75, 286),
        new LatLonAlt(34.5970415, -119.707031, 883),
        new LatLonAlt(30.6000938,  -83.1445312, 53),
        new LatLonAlt(41.902277, -73.828125, 106),
        new LatLonAlt(39.1676014, -76.8658447, 180)
    };

polyLineInfo.AltitudeMode = AltitudeMode.FromGround;
polyLineInfo.LineColor = System.Drawing.Color.Yellow;
polyLineInfo.LineWidth = 15;

GlobeControl.Host.Geometry.AddGeometry(new PolygonGeometry("route", "route", null, points.ToArray(), PolygonGeometry.PolygonFormat.Polygon3D, polyLineInfo));

Aug 2, 2011 at 11:43 AM

Meant to reply back. We were able to figure this out. Turns out, we needed to initialize with the CreateUsingDegrees() method:

 

List<LatLonAlt> points = new List<LatLonAlt>
    {
        LatLonAlt.CreateUsingDegrees(48.4583518, -123.75, 286),
        LatLonAlt.CreateUsingDegrees(34.5970415, -119.707031, 883),
        LatLonAlt.CreateUsingDegrees(30.6000938,  -83.1445312, 53),
        LatLonAlt.CreateUsingDegrees(41.902277, -73.828125, 106),
        LatLonAlt.CreateUsingDegrees(39.1676014, -76.8658447, 180)
    };