Hi everyone,
I've a problem with drawing on map on ArcGIS SDK 100.7 for .NET.
I'm using SketchEditor and I need to configure visibility of a button with SketchEditor.CompleteCommand.CanExecute.
My problem is that the execution of my test is always done before the drawing.
Sequence step by step :
- //Step 1
- Geometry g = await MapView.SketchEditor.StartAsync(SketchCreationMode.Point, true); //Async method
- MapView.SketchEditor.CompleteCommand.CanExecute(null); //Return false
- //Step 2 : Click on the map
- MapView.SketchEditor.CompleteCommand.CanExecute(null); //Return false
- //The 1st drawing appears on the map
- //Step 3 : Click on the map
- MapView.SketchEditor.CompleteCommand.CanExecute(null); //Return true but detect only 1st point instead of 1st & 2nd.
- //The 2nd drawing appears on the map
My goal is to detect the first point into my first control.
The difficult is my initialisation are asynchrone, but my control is synchrone.
I tried to pass the 2 asynchronously but the error is still present.
Currently, my button appears when creating the 2nd point. I have the same problem for polylines and polygons. My button appears at the 3rd point for my polyline, and at my 4th point for my polygon. There is always a point of delay.
Have you got any idea?
Thank you
I'm sorry but I am missing something, I don't understand how a point would not be valid to complete the polygon and why one would want to confirm.
CompleteCommand can only be executed when you have a geometry already. It allows you to accept (finalize) that geometry. As opposed to moving a vertex before finishing. If you want the level of control you seem to desire and validate each point then you pretty much would need to just create your own editor and use the passed in point to draw a graphic on a graphics layer.
Again, I may just not understand what you are really trying to accomplish and apologize if that is the case
Sorry, I d'on't see how explain.
I have a hidden button and I want to alter his visibility.
At begin, button are hidden.
Next, we start drawing.
When at least one point is drawn, I want the button to appear.
The visibility depends on the drawing but also on another variable, so a "Binding" is not enough.
The real problem is the order of execution, when we clicked on the map, the GeoViewTapped event runs before the new point of the drawing.
Since I check the visibility in this event, I'm always one point behind. When I draw the 2nd point, my check only detects the first point. Same with more points.
The ICommand interface should deal with automatically enabling/disabling the button, so if you don't want to hide the button this will work exactly like you want just by binding the Command to the button.
If you do want to hide the button, you would override the visual state of the button to instead collapse it, instead of disabling it. See: wpf - how to hide a button that is bound to a command that cannot execute? - Stack Overflow
I tried your method but the order of runs don't change.
With breakpoint, I see the Icommand runs before drawing modify.
It's the same problem.
Here is my updated code:
<AppBarButton Margin="0,0,-15,0"
Command="{Binding ValiderTraceCommand}"
Icon="Accept"
Label="Valider le tracé"
Style="{StaticResource DefaultAppBarButtonStyle}"
Visibility="{Binding ValiderTraceCommandIsVisible, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" Width="100" FontSize="10"/>
public bool ValiderTraceCommandIsVisible
{
get
{
return MapView.SketchEditor.CompleteCommand.CanExecute(null);
}
}
I think I'm at a point where I just don't understand what you're trying to achieve. I don't get what you mean by the order of commands. Commands don't execute until you press the button they are bound to. Perhaps there's just a misunderstanding of what these commands are used for. Also you don't have to use the commands, but can just execute methods on the SketchEditor yourself.
When we clicked, they are many action that take in place. These actions are not launched simultaneously.
So there is an order of execution. This order is :
- ICommand (Visibility)
- GeoViewTapped
- The point is drawn
The point is drawn after all the other actions. That's the problem.
Is this the code you have?
- //Step 1
- Geometry g = await MapView.SketchEditor.StartAsync(SketchCreationMode.Point, true); //Async method
- MapView.SketchEditor.CompleteCommand.CanExecute(null); //Return false
If so, the second line of code won't run until the draw has completed, because you're awaiting the draw to complete. Remove the await if that's what you want.
Task<Geometry> drawTask = MapView.SketchEditor.StartAsync(SketchCreationMode.Point, true);
[...run other core... ]
Geometry g = await drawTask;
Sorry, I understand my mistake, I misspoke.
SketchEditor.CompleteCommand.CanExecute runs in an other method.
When CanExecute runs, StartAsync isn't finished.
I want to detect when CanExecute is true before the end of StartAsync.
> I want to detect when CanExecute is true before the end of StartAsync.
You'll need to listen to the CompleteCommand.CanExecuteChanged event to be notified if the command's CanExecute has potentially changed, then call CanExecute(...) each time it fires to check the status.
Ie something along the lines of:
SketchEditor.CompleteCommand.CanExecuteChanged += (s,e) => { if(SketchEditor.CompleteCommand.CanExecute(null)) { DoSomething(); } };
Geometry g = await MapView.SketchEditor.StartAsync(SketchCreationMode.Point, true);
I'm just now realizing you're drawing a point. Point geometry completes immediately when you click.