Shape not saved to layer

Hello,

I use a polygon to mark a region on the map. I use the cursormode cmEditShape to edit the polygon. I want to be able to move the polygon (without accidentally changing it’s shape) and use a different mode for that. Because I couldn’t get the cursormode cmMove to work this is what I use to move the shape.

private void AxMap1_MouseUpEventRelocate(object sender, _DMapEvents_MouseUpEvent e)
{
double projX = 0.0;
double projY = 0.0;
axMap1.PixelToProj(e.x, e.y, ref projX, ref projY);
m_markerPoint.x = projX;
m_markerPoint.y = projY;
Point centroidPoint = m_regionShape.Centroid.Clone();
m_regionShapefile.Move(m_markerPoint.x - centroidPoint.x, m_markerPoint.y - centroidPoint.y);
axMap1.Redraw();
}

This works, but if I use cmEditShape first and only select and deselect the shape without changing it’s position or vertices the centroidPoint doesn’t change anymore.
I suspect the edit mode isn’t ended properly. Does anyone have an idea what can be done?

Thanks in advance!

Hello @gdi

I’m sorry for such a delayed response. I’ve looked at this a few times, but I don’t think I understand exactly what you’re saying. I probably need to set up an identical test to see the behavior.

I think you’re saying

  1. the editor’s built-in move did not work properly
  2. so instead, you implemented your own move, which works
  3. BUT, if you first start editing, selecting the shape, then your move no longer works because… and here I’m not sure what you mean by “the centroid doesn’t change anymore”.

Is it possible that you should not be mixing the built-in editing and your own editing? You’ve invoked the editing tool by selecting the shape, and you have to ‘let go of it’, perhaps by ‘Clear’ ing the editor. Or perhaps you should turn off interactive editing for that layer so that the built-in editing can’t interfere with your editing.

I hope to be able to set up a test soon so that I can better understand the problem. And if there’s a bug in our editing (moving) then we can hopefully address it.

Regards.
Jerry.

Hello Jerry,

To elaborate on your points:
I couldn’t get the built-in move to work, but we want to be able to move a small polygon (<10ha) to different continents. Therefore my solution to move the polygon to where the user clicks is a good solution for us.
The centroid is a built-in property which I use to calculate the offset of the vertices (the user clicks where new position of the centroid should be). The centroid isn’t updated, but neither are the vertices of the polygon although the user sees the polygon in a different location. The cmEditShape needs the user to click on the map outside of the polygon that is being edited to exit edit mode for that polygon. The problem I have is that a user can use my relocate mode or click the savePolygonVertices() function while the cmEditShape isn’t properly ended.

When I use ShapeEditor.Clear() the editor exits correctly, but also discards the changes the user made.
Calling these two functions in succession does work:
axMap1.ShapeEditor.SaveChanges();
axMap1.ShapeEditor.Clear();

Thanks for the input, it really helped me to find the correct functions to call!

Gregoor