ThinkGeo.com    |     Documentation    |     Premium Support

Moving feature to mouse click location

I’m trying to move a feature to the location I click at on the mouse. For anything other than a point, the mouse click location will be the new center location of the feature.

Originally I was just updating the shape, and it was moved to the mouse location, but I noticed the actual Feature was still at the old location:

 var shape = (PolygonShape)myFeature.GetShape();
 var centerPolyPoint = shape.GetCenterPoint();
 var mousePoint = new PointShape(e.WorldX, e.WorldY);

 double xOffSet = Math.Abs(mousePoint.X - centerPolyPoint.X);
 double yOffset = Math.Abs(mousePoint.Y - centerPolyPoint.Y);


myLayer.EditTools.BeginTransaction();
shape.TranslateByOffset(xOffSet, yOffset);
myLayer.EditTools.Update(shape);
myLayer.EditTools.CommitTransaction();

So how can I update the actual feature and not just the shape?

Hi Dan,

I want to know what’s the type of “myLayer”, does it a shape file feature layer or inmemory feature layer?

If you think update API don’t works, please try to delete the shape and add the new one back.

Regards,

Ethan

It is an InMemoryFeatureLayer.

What is happening is that the Feature’s shape is being updated with the new vertices, but the Feature itself still shows the old vertices after the CommitTransaction().

Deleting and re-adding the feature seems to work, but it does seem like an unnecessary action. I think a good thing to add into MapSuite would be the ability to move the actual feature.

Hi Dan,

I tested your code, but it looks your code works well.

Please view attached sample project:

9540.zip (101.6 KB)

Regards,

Ethan