Pierre-Antoine
 Level 3 Posts:78
 |
|
|
Hello everyone,
I would like to know how can I disable the right click on my TrackOverlay ?
I want to disable it because I have a context menu and when I right-click, the context menu is shown but it's also adding a vertex in the track shape layer !
And I also want to know how can I remove the last vertex added in the trackshapelayer ? I have this option in my context menu but I can't do it !
Thanks in advance.
Pierre-Antoine |
|
Pierre-Antoine DOUCHET IT Developer / www.geosys.com
|
|
|
Adolfo
 Level 1 Posts:26
 |
|
|
My suspicion is that you would have to create a new class inheriting from TrackInteractiveOverlay and overriding methods like MouseDownCore.
Something similar has been done to EditInteractiveOverlay in Code Community projects such as the last one Editing Rectangles.
http://code.thinkgeo.com/projects/s...rectangles
There might be another more straightforward way to do that using winformsMap1.TrackOverlay.TrackShapeLayer.
Yale or someone from the Desktop team should have a more concrete answer on that. |
|
|
|
|
James
 MVP Posts:401

 |
|
|
Thank Adolfo for your sharing and your suggestion is quite right. Pierre, If you override the MouseDownCore, you can check the mouse button from the pass-in parameter interactionArguments, if it is right button, doesn't do anything that can be disable the right click. Please let me know if you need to more information about it. Thanks James
|
|
| Think what? Think Geo! |
|
|
Pierre-Antoine
 Level 3 Posts:78
 |
|
|
Hello,
Thanks for your answer. I'm going to try this solution.
Pierre-Antoine |
|
Pierre-Antoine DOUCHET IT Developer / www.geosys.com
|
|
|
James
 MVP Posts:401

 |
|
|
Pierre-Antoine, Thanks for your quick respnse. Just let me know the result after you try. Thanks James |
|
| Think what? Think Geo! |
|
|
Pierre-Antoine
 Level 3 Posts:78
 |
|
|
James,
This solution works. Thanks.
About my other problem, I use this code to remove the last vertex added but it doesn't work :
winformsMap1.TrackOverlay.Lock.EnterWriteLock();
try
{
Feature feature = winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures["InTrackingFeature"];
if (winformsMap1.TrackOverlay.TrackMode == TrackMode.Polygon)
{
PolygonShape polygon = feature.GetShape() as PolygonShape;
Vertex lastVertex = polygon.OuterRing.Vertices.Last();
polygon.OuterRing.Vertices.Remove(lastVertex);
}
else if (winformsMap1.TrackOverlay.TrackMode == TrackMode.Line)
{
LineShape multiline = feature.GetShape() as LineShape;
Vertex lastVertex = multiline.Vertices.Last();
multiline.Vertices.Remove(lastVertex);
}
winformsMap1.TrackOverlay.TrackShapeLayer.FeatureSource.Open();
winformsMap1.TrackOverlay.TrackShapeLayer.FeatureSource.BeginTransaction();
winformsMap1.TrackOverlay.TrackShapeLayer.FeatureSource.UpdateFeature(feature);
winformsMap1.TrackOverlay.TrackShapeLayer.FeatureSource.CommitTransaction();
winformsMap1.TrackOverlay.TrackShapeLayer.FeatureSource.Close();
}
finally
{
winformsMap1.TrackOverlay.Lock.ExitWriteLock();
}
winformsMap1.Refresh(winformsMap1.TrackOverlay);
How can I modify this code to make it work ?
Thanks. |
|
Pierre-Antoine DOUCHET IT Developer / www.geosys.com
|
|
|
Pierre-Antoine
 Level 3 Posts:78
 |
|
|
Hi again,
I try to create a method in my custom trackinteractiveoverlay to modify the vertex collection like this :
public class CustomTrackInteractiveOverlay : TrackInteractiveOverlay
{
public CustomTrackInteractiveOverlay() : base()
{
}
protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
{
if (interactionArguments.MouseButton != MapMouseButton.Right)
return base.MouseDownCore(interactionArguments);
else
return new InteractiveResult();
}
public void RemoveLastVertexAdded()
{
Vertex lastVertex = this.Vertices[this.Vertices.Count - 2];
this.Vertices.Remove(lastVertex);
}
}
The last vertex added is removed but nothing change in the trackshapelayer. And if I try to remove another vertex, I've got an exception (Argument out of range).
Is it the right way to do this ?
Thanks. |
|
Pierre-Antoine DOUCHET IT Developer / www.geosys.com
|
|
|
Val
 MVP Posts:403

 |
|
|
I have the following CustomTrackInteractiveOverlay and I use it to track lines at left click and remove the last vertex at right click. It is working just fine for tracking lines but if I try to do the same thing with tracking a polygon I have the same "out of bound" error. I think it should work as well for tracking polygons. I think that there is a bug. I communicated this to the Desktop team and we will see what they say. Thank you.
CustomTrackInteractiveOverlay customTrackInteractiveOverlay = new CustomTrackInteractiveOverlay();
customTrackInteractiveOverlay.TrackMode = TrackMode.Line;
winformsMap1.TrackOverlay = customTrackInteractiveOverlay;
class CustomTrackInteractiveOverlay : TrackInteractiveOverlay
{
public CustomTrackInteractiveOverlay()
: base()
{
}
protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
{
if (interactionArguments.MouseButton != MapMouseButton.Right)
return base.MouseDownCore(interactionArguments);
else
RemoveLastVertexAdded();
return new InteractiveResult();
}
private void RemoveLastVertexAdded()
{
int minVertex = 0;
if (this.TrackMode == TrackMode.Line) minVertex = 2;
else if (this.TrackMode == TrackMode.Polygon) minVertex = 3;
if (this.Vertices.Count > minVertex)
{
this.Lock.EnterWriteLock();
try
{
Vertex lastVertex = this.Vertices[this.Vertices.Count - 2];
this.Vertices.Remove(lastVertex);
}
finally
{
this.Lock.ExitWriteLock();
}
}
}
}
|
|
|
|
|
James
 MVP Posts:401

 |
|
|
Val,
It's a bug that we have a private member variable which is used to track polygon, now you override some logic, so the value of it is not right but you can not update it as well.
I have tried many ways to find a workaround but I can not make it, so I added this to our Issue Tracking system, we will fix it later.
Thanks
James |
|
| Think what? Think Geo! |
|
|
Pierre-Antoine
 Level 3 Posts:78
 |
|
|
Hello,
Thank you for your fast answer. I would keep in touch to know when it will be fixed.
Have a good day ! |
|
Pierre-Antoine DOUCHET IT Developer / www.geosys.com
|
|
|
Val
 MVP Posts:403

 |
|
|
Yes, this bug should be fixed soon. In the meantime, I suggest you check out the new project in the Code Community Custom Line Track.
http://code.thinkgeo.com/projects/show/customtrackline
It shows the behavior you are looking for with a line. For having the same thing with polygon, it should be almost identical and you can have it working once the bug will be fixed. Thank you. |
|
|
|
|
James
 MVP Posts:401

 |
|
|
Val,
We have fixed the problem with version 3.1.398 that made the MouseDownCount as protected that we can support polygon, when you try to remove a vertex you need to subtract 1 for mouse down count. Here is updated code:
class CustomTrackInteractiveOverlay : TrackInteractiveOverlay
{
public CustomTrackInteractiveOverlay()
: base()
{
}
protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
{
if (interactionArguments.MouseButton != MapMouseButton.Right)
return base.MouseDownCore(interactionArguments);
else
RemoveLastVertexAdded();
return new InteractiveResult();
}
private void RemoveLastVertexAdded()
{
int minVertex = 0;
if (this.TrackMode == TrackMode.Line) minVertex = 2;
else if (this.TrackMode == TrackMode.Polygon) minVertex = 3;
if (this.Vertices.Count > minVertex)
{
this.Lock.EnterWriteLock();
try
{
Vertex lastVertex = this.Vertices[this.Vertices.Count - 2];
this.Vertices.Remove(lastVertex);
this.MouseDownCount--;
}
finally
{
this.Lock.ExitWriteLock();
}
}
}
}
Thanks
James |
|
| Think what? Think Geo! |
|
|