Select to view content in your preferred language

Draw object - mouse last position used in Addvertex

610
4
07-19-2011 02:29 AM
MatthewPilgrim
Regular Contributor
Hi,

We have a floatable window which when an 'Add' button is pressed takes two text coordinates and creates a new map point with the correct spatial reference.  This is passed to a geometry service for projection.  When this completes the point is added to the map.  This works well for a single point and the first point of a line.  However for the second point of a line as the mouse goes over the add button end of the line (that???s tracking the mouse) freezes (as expected).  When you press the add button its this frozen point that is used for the lines 2nd point.  The strange thing is if you break on this line:

_DrawObject.AddVertex(resultMapPoint);

The resultMapPoint correlates to the user input (easy to check when no projection is required due to matching spatial references) Not the frozen point.

So at some point the draw object is using the last position of the lines endpoint to add a vertex.  Also note the point entered by the user appears to be used for another vertex (3rd one) but disappears when the mouse moves off of the button.

Can anyone explain this behaviour and offer a work around etc?

Thanks, Matt
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
I am updating this sample to  mimic what you are trying to do in your Silverlight app: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Project

I added the following resource:
<esri:SimpleLineSymbol x:Key="DrawLineSymbol" Color="Green" Width="4" />
<esri:SimpleFillSymbol x:Key="DrawFillSymbol" Fill="#3300FF00" BorderBrush="Green" BorderThickness="2" />   
<esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="#33FF0000" BorderBrush="Red" BorderThickness="2" />


Added a button to complete draw:
 <Button Content="Complete" Margin="0,5,5,0" Click="Button_Click" />


And the following code InitializeComponent():
 draw = new Draw(MyMap)
 {
  LineSymbol = LayoutRoot.Resources["DrawLineSymbol"] as LineSymbol,
                FillSymbol = LayoutRoot.Resources["DrawFillSymbol"] as FillSymbol,
  DrawMode = DrawMode.Polygon,
  IsEnabled = true
 };
 draw.DrawComplete += draw_DrawComplete;
}

Draw draw;
void draw_DrawComplete(object sender, DrawEventArgs e)
{
 graphicsLayer.Graphics.Add
 (new Graphic()
 {
  Geometry = e.Geometry,
  Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol
 });
 MyMap.PanTo(e.Geometry);   
}

private void Button_Click(object sender, RoutedEventArgs e)
{
 draw.CompleteDraw();
 draw.IsEnabled = false;
}


I modified the code to add vertex instead of adding graphic to the map:
draw.AddVertex(resultMapPoint);
//graphicsLayer.Graphics.Add(resultGraphic);


I think this is what you are trying to do but I did not get application to freeze.
0 Kudos
MatthewPilgrim
Regular Contributor
Jennifer,

Thanks for taking time to try this.  My drawmode is polyline.  Also can you confirm that you are taking the value typed in, projecting it and then using the resulting projection as the resultMapPoint. 

So you should get this behaviour:
1) type in co-ords and press Add.
2) Line started on screen - moving the mouse moves the loose end of the line (point 2).
3) move mouse over co-ord dialog - as you do the line stops redrawing (freeze as expected)
4) change X co-ord and press Add.
5) you should get a second point to make a horizontal line, with the free end of the line (now point three) following the mouse (when not over the dialog).

For step 5 I get: a point (2nd) where the line froze in step 3 and 3rd point corresponding to the co-ord specified in step 4.  When I move the mouse the last point disappears.

I do not have a complete button yet!

Matt
0 Kudos
JenniferNery
Esri Regular Contributor
I still cannot get the app to freeze by following your steps.

But I do see that MouseMove, updates the location of added vertex. This seems like a bug. We'll try to fix this in future versions of the API.

If you can, please try to follow the code changes in my previous post and let me know if the app still freezes. To have this sample to work with Polyline, you need to change DrawMode and add a DefaultLineSymbol in your resources.
0 Kudos
MatthewPilgrim
Regular Contributor
I apologize if the term �??freeze�?? has misled you.  By this I meant when the mouse pointer moves over the dialog I use to enter the coordinates it no longer update the line been drawn (from the last point to the mouse). i.e. the line freezes not the application.

Thank you for acknowledging the other issue and offering to fix it in a forthcoming version. 

Can I suggest that the Draw object is extended a little to make it more flexible?  For example adding events for before and after a point being added.  Where they offer the ability to cancel the point or mark it as handled.  Also exposing the temporary collection of vertex that are being added would be useful in all events.  Scenarios where this help include:

  1. Writing your own �??snap�?? code where the point the user clicks is changed to a point on top of some other geometry (either in a BeforeAdd event by changing the e.NewPoint or in an AfterAdd event by removing the last point and adding another.  Note I�??ve tried the latter approach and without access to the vertices it�??s hard to know if it the first point or not - so you could also add a flag for FirstPoint and LastPoint.

  2. Writing a coordinate type-in where at any point during the draw process (including the first point) the user can type in an x/y pair and hit a button.  This would call draw.addVertex as describe in the thread above.

  3. Validating the users input, i.e. require a 5 sided polygon or a shape with an area > x miles.  This could be checked on AddPoint event and the point rejected if it is not valid.

Hope this helps the development effort,

Matt
0 Kudos