I have the following method in my mapview.xaml.cs file:
private void LogCurrentPosition()
{
switch (ViewModel.CurrentGeometryType)
{
case GeometryType.Line:
// TODO: do stuff
break;
case GeometryType.Polygon:
Vertex vertex = new Vertex((double)LastGgaMessage.Longitude, (double)LastGgaMessage.Latitude);
Feature feature = new Feature(vertex);
ManagedProj4Projection projection = new ManagedProj4Projection(ManagedProj4Projection.GetWgs84ParametersString(), ManagedProj4Projection.GetGoogleMapParametersString());
projection.Open();
feature = projection.ConvertToExternalProjection(feature);
wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Add(feature);
wpfMap1.TrackOverlay.Refresh();
break;
case GeometryType.Point:
// TODO: do stuff
break;
}
}
What we have is an application that the user can draw shapes onto. This particular function is with a GPS. When they have the GPS on and the map set to GPS mode, the user will click a button on a screen to start a polygon (set the trackmode) and then a second button to log the current position he/she is at as part of the polygon. The above method runs when the log button is selected. The issue I have is that this is not actually dropping a point on the screen at all…what it should be doing is putting it down as the first point in the polygon, the second time the select it have it be the second point, etc.
What do I have wrong?
Drawing shape from gps
In addition, it would be nice to turn off manual mode. In other words, is there a way to set it up so that if the user clicks on the screen it will not plot a polygon point, even with the trackmode set to polygon. We would like to restrict it to just plotting based on gps location as specified above.
Even when I have the following (for testing purposes…though this wouldn’t be sufficient since the user wouldn’t see the polygon as it is drawn), nothing shows up:
private void LogCurrentPosition() { switch (ViewModel.CurrentGeometryType) { case GeometryType.Line: // TODO: do stuff break; case GeometryType.Polygon: Vertex vertex = new Vertex((double)LastGgaMessage.Longitude, (double)LastGgaMessage.Latitude); ringShape.Vertices.Add(vertex); break; case GeometryType.Point: // TODO: do stuff break; }
private void StopButtonCommand() { ringShape.Vertices.Add(new Vertex(ringShape.Vertices[0].X, ringShape.Vertices[0].Y)); for (int i = 0; i < ringShape.Vertices.Count; i++) { wpfMap1.TrackOverlay.MouseDown(new InteractionArguments() { WorldX = ringShape.Vertices.X, WorldY = ringShape.Vertices.Y }); } wpfMap1.TrackOverlay.MouseDoubleClick(new InteractionArguments()); }
Hi Scott,
Thanks for your post,
For your first problem, attached "DynamicAddVertex.txt" is for your reference, and here is also a test video on our end for your iformation:screencast.com/t/FNwIeCQuMO0
For your second problem, attached "DisableManualMode.txt" is for your reference.
if you have any more question , please feel free to let us know.
Best Regards
Summer
DisableManualMode.txt (615 Bytes)
DynamicAddVertex.txt (1.21 KB)
Thank you very much for your help and the code samples!
What I am having an issue with is when there is no polygon to start with. In our scenerio, I will set the TrackMode to Polygon and then at that point the user will start recording their GPS as locations as they start walking. So I need to draw the polygon as they start logging their points. In your sample, you already had an existing Polygon. I need one for if there isn’t one yet and we are creating one.
From what I am gathering, you need four points on a polygon’s outerring before adding it. This is what I have so far, but nothing is showing up:
private void LogCurrentPosition()
{
switch (ViewModel.CurrentGeometryType)
{
case GeometryType.Line:
// TODO: do stuff
break;
case GeometryType.Polygon:
// TODO: Assume new polygon for testing purposes.
Vertex vertex = new Vertex((double)LastGgaMessage.Longitude, (double)LastGgaMessage.Latitude);
PolygonShape Polygon = new PolygonShape();
if (wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count > 0)
{
Polygon = wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count - 1].GetShape() as PolygonShape;
}
List<vertex> listForInsertingVertex = new List<vertex>(Polygon.OuterRing.Vertices);
if (listForInsertingVertex.Count > 0)
listForInsertingVertex.RemoveAt(listForInsertingVertex.Count - 1);
listForInsertingVertex.Insert(0, vertex);
listForInsertingVertex.Add(vertex);
listForInsertingVertex.Add(vertex);
listForInsertingVertex.Add(vertex);
foreach (Vertex vert in listForInsertingVertex)
{
Polygon.OuterRing.Vertices.Add(vert);
}
try
{
wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Add(new Feature());
wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count - 1].WellKnownBinary = Polygon.GetWellKnownBinary();
wpfMap1.TrackOverlay.Refresh();
}
catch (Exception e)
{
throw (e);
}
break;
case GeometryType.Point:
// TODO: do stuff
break;
}
}
so, in the preceding sample, when that code is first hit the count for wpfMap1.TrackOverlay.TrackShapeLayer.Count is 0. So I am assuming that I will need to add the internal feature first, along with the initial point of the polygon, which again I am adding four times because it says the OuterRing of the Polygon needs 4 verticies. Please help me understand where I am going wrong.
Alternatively I thought about just invoking the MouseDown since that would be easiest, but I wasn’t sure how to convert my lat/long coordinates into the InteractionArguments object that the MouseDown/MouseClick method needs passed into it. Specifically, I guess it was converting those coordinates into X/Y coordinates.
Well I got it to work for polygon’s if I wait to start drawing until the user has submitted three points. Is that the only way to do it?
Hi Scott,
Thanks for your further information, attached code is for your reference, and here is a test vedio on our end:screencast.com/t/4yjUwgGz
if you have any more question , please feel free to let us know.
Best Regards
Summer
Post11575.txt (2.98 KB)
Beautiful! Thank you!
Hi Scott,
Great to hear it is sorted out, if you have any more question, please feel free to let us know.
Best Regards
Summer