# Moving feature to mouse click location

**URL:** <https://community.thinkgeo.com/t/moving-feature-to-mouse-click-location/9540>\
**Category:** WPF\
**Created:** [June 24, 2019, 5:12pm UTC](https://community.thinkgeo.com/t/moving-feature-to-mouse-click-location/9540 "2019-06-24T17:12:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Weaver](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@Dan\_Weaver](https://community.thinkgeo.com/u/Dan_Weaver)\
**Post date:** [June 24, 2019, 5:12pm UTC](https://community.thinkgeo.com/t/moving-feature-to-mouse-click-location/9540/1 "2019-06-24T17:12:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [June 25, 2019, 5:22am UTC](https://community.thinkgeo.com/t/moving-feature-to-mouse-click-location/9540/2 "2019-06-25T05:22:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dan\_Weaver](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@Dan\_Weaver](https://community.thinkgeo.com/u/Dan_Weaver)\
**Post date:** [June 25, 2019, 7:49pm UTC](https://community.thinkgeo.com/t/moving-feature-to-mouse-click-location/9540/3 "2019-06-25T19:49:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [June 26, 2019, 7:29am UTC](https://community.thinkgeo.com/t/moving-feature-to-mouse-click-location/9540/4 "2019-06-26T07:29:44Z")

</div>

Hi Dan,

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

Please view attached sample project:

[9540.zip](https://community.thinkgeo.com/uploads/default/original/3X/e/1/e189933c08e6c9dc9a011336df381c9752a46287.zip) (101.6 KB)

Regards,

Ethan
