Draw Polyline on shpfile

I’m trying to draw ployline on a shpfile. But when i drew it using MouseDownevent, shpfile disappeared.
although i already set

axMap1.SendMouseDown = true;
axMap1.MouseDownEvent += AxMap1MouseDownEvent;

and this is my code.

I’m not sure what you mean by your shapefile disappearing.

One thing I think I see relates to your pt variable. It looks like you are re-using your instance of pt, which effectively overwrites each x, y coordinate on each MouseDown event. So you’re adding multiple references to the same point to your list. Your geometry is a stack of identical points.

You should declare a local pt variable, something like

Point pt = new Point();
pt.X = e.x;
pt.Y = e.y;

Regards,
Jerry.

humm… i am only using Point in MouseDownEvent. And it work well like below.

But when i opened new shapefile, the polyline disappeared continuously . And when i tried to draw polyline, the shapefile disappeared.

Hello @james

I’m sorry that I’m not understanding your situation. It would helpful to have more context, more code than just the MouseDown event. Then we would be able to see

  1. where and how your variables are declared
  2. how you are opening and loading a shapefile that is making the polyline disappear, and
  3. how the polyline drawing might be making the shapefile disappear

Respectfully,
Jerry.

This is the code before MouseDownEvent

Hello @james

  1. Your drawing is disappearing every time you load a shapefile because you call axMap1.Clear. This clears the drawing layers as well as the data layers. If you want, you can instead call axMap1.RemoveAllLayers to clear just the data layers and leave the drawing layers alone.

  2. I’m pretty sure that your shapefile is ‘disappearing’ on the mouse click because you are resetting your map extent. Your shapefile is still there, but you are simply ‘panning’ away from it. You are resetting your map extent and drawing your line, but you are doing so using screen coordinates (pixels) rather than spatially referenced map coordinates. This is effectively changing your map viewport and drawing your line in the vicinity of [0, 0]. You can see this in the image you attached of your drawn line. The coordinates (lat, lng) are very near [0, 0]. Try changing the one line in your mouse down event as follows:

    int handle = axMap1.NewDrawing(tkDrawReferenceList.dlSpatiallyReferencedList);

Regards,
Jerry.

Thanks Jerry
What you told me was very helpful.
i thought points’ coordinate was the matter.
so i added axMap1.PixelToProj(e.x, e.y, ref x, ref y);
before axMap1.DrawLineEx(handle, x1, y1, x2, y2, 3, 300);
And it works well. Thank you again.

Respecfully,
James