Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using Mapstraction to make a web-based mapping system. The documentation has some serious holes in it. I would like to use Mapstraction to draw polygons with holes in them. Serious holes.

Can anybody tell me how I can do this?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

I can't find a polygon class and class mxn.Polyline seems only to be able to "mark a polyline as closed." This probably will not suffice for managing non-simply-connected polygons unless you can figure out how to handle disconnected polylines and try to close a set of them, hoping that the process will be done correctly.

A standard workaround for representing such polygons is to make "keyhole cuts" from the outside into each hole. For example, consider the annulus bordered by concentric circles of radii 1 and 2. Relative to their common origin you might make a cut from (2,0) to (1,0). The boundary of the resulting polygon begins at (2,0), goes straight to (1,0), follows the inner circle clockwise all the way around and back to (1,0), returns to (2,0), follows the outer circle counterclockwise all the way around and back to the starting position of (2,0). Throughout this traversal the polygon's interior lies to the left.

This picture from Webster's online dictionary roughly illustrates the idea. The inner circle in the picture is intended to be very small. The portions Gamma_1 and Gamma_3 are supposed to coincide but are drawn separately to help you trace the polyline.

Keyhole cut

You might pay a price for making such cuts depending on how the polygons are displayed. Ideally, overlapping portions of a boundary having opposite orientations (like Gamma_1 and Gamma_3) should cancel out and not be drawn at all, but it's unfair to expect a polygon rendering procedure to check for such overlaps. Thus, the cuts will likely be visible. A workaround for that is to draw such polygons with invisible boundaries and separately draw the polylines that form their proper (uncut) boundaries. Not a great solution, but you might find it serviceable in your application.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.