This project is read-only.

Drawing on top of a shapefile

Nov 24, 2010 at 4:31 PM


I'm developing an application which shall display a map (shapefile) and be able to draw "contacts"(points) on top of it.

I'm able to load the shape (which gets the handle 0) and create a new drawing on it (which gets also the handle 0) and draw a square on the map (my position). When I do ClearDrawing to redraw my new position, the map disapears.

Can anybody explain me why this happens???

Any help is appreciated,

Goncalo Valadas

Nov 25, 2010 at 1:15 AM

Hi Goncalo,

I think your problem is your handle number.

When you use Cleardrawing you have to specify the handle, so you erase your shapefile doing this.

I hope it helps you,

Best regards


Nov 25, 2010 at 10:10 AM

Hello Laurent,

Thanks for your quick answer. That is what I suspected. So how can I create two layers: A bottom one with a shapefile and a drawing layer on the top of it?

I try several times and the drawing handle returned by NewDrawing is dependent of the number of layers on the map. Should I create an empty shapefile and draw on it ?

Do you have any sample code how to do this?

Best regards,


Nov 25, 2010 at 9:12 PM

Do something like this to make it dynamic.

dim hRoutes as integer

hRoutes = OpenShapefile()

dim hContacts as integer

hContacts = NewDrawing

Its pseudo code but you get the idea. each function should return the handle and so should each shapefile you add. you can then use these handles in other code like





Nov 26, 2010 at 9:31 PM

I understood the Drawing layer as something different from from other map (shapefile, image) layers. So when you use ClearDrawing it clears all objects drawed on drawing layer. ClearDrawing is not intended to redraw new position.

I think that if you need to store your contact points than yes it would be better to use another shapefile layer to store them there.

In my case I had to do some digitizing on screen and use drawing layer. I was a bit confused about that I did not found method how to add a point in existing poligon of a drawing layer. I had to show the polygon digitized so far after a click, so I made a script that on each mouse click uses ClearDrawing, NewDrawing and draws (DrawPoint, DrawLine, DrawPolygon) corresponding map objects in Drawing layer.

But I am not sure was my approach right. On larger data sets the script was a bit slow.

Please correct me if there is some more effective way!



Dec 3, 2010 at 7:53 PM


the support of drawing layers in MapWinGis is quite poor indeed and I thought about the issue before. I added a record in the issue tracker about this: Comment it if you have more thoughts on the issue.



Dec 27, 2011 at 6:52 PM

  I have a similar issue in version 4.8. In version 4.7 I would open a shapefile of states and use the AddLayer(object, visibility) function to add it to the control. Later in the app, I would use NewDrawing(projectiontype) to create a new drawing layer and then draw circles or polygons or whatever data on that new layer. The NewDrawing() function would create a new layer and return a valid handle.

  In 4.8, the NewDrawing() function does not seem to create a new layer and the handle it returns is the same as the first layer that was added using the AddLayer() function.