drawing polygons with holes

1.103 görüntüleme
İlk okunmamış mesaja atla

frauseifert

okunmadı,
8 Haz 2011 09:57:538.06.2011
alıcı mapsforge-dev
hello!

I'm searching for a possibility to draw overlays that are polygons
with holes, just like in this KML-example:

http://freegeographytools.com/2008/a-simple-online-kml-polygon-creator-with-holes

Is it possible with mapsforge?


Inessa

mueh...@inf.fu-berlin.de

okunmadı,
8 Haz 2011 13:42:248.06.2011
alıcı mapsfo...@googlegroups.com, frauseifert
Hello Inessa,

yes, it is possible (see the yellow polygon on the attached screenshot).
The mapsforge map library currently uses the 2D "Canvas" API from the
android.graphics package internally for all drawing operations (which is
actually an adapter for the Skia library, see:
http://code.google.com/p/skia/). If you want to add a polygon with one
or several holes (technically each "hole" is a polygon as well), all you
have to do is to set the GeoPoints of each polygon in the correct order
on your OverlayWay.

Example: the outer polygon is a triangle with nodes a1, b1 and c1. The
inner polygon is also a triangle with nodes a2, b2 and c2. In order to
draw the OverlayWay correctly the way node array must look like:
[a1, b1, c1, a1, a2, b2, c2, a2]
Each polygon must be closed, which means that the first and last
GeoPoint are equal. If more than one inner polygon is needed, just add
them in the same way to the array.

This was the theoretical part of the answer. Practically while i was
trying to generate the example screenshot, i found a little bug in the
WayOverlay class. Inner polygons could never make a hole in an outer
polygon due to that mistake. I already fixed it and committed everything
in revision r1127 (see
https://code.google.com/p/mapsforge/source/detail?r=1127). If you check
out the latest version from our repository, everything should work as i
just explained.

Please let me know in case the bug is not solved for you or further
problems arise.

Best regards,
Thilo

multipolygon.png
signature.asc

Inessa Seifert

okunmadı,
10 Haz 2011 10:11:1310.06.2011
alıcı mueh...@inf.fu-berlin.de, mapsfo...@googlegroups.com
Dear Thilo,

I've tried to add to an OverlayWay the following list of geo points:

pointList = [52531290,13336468,
 52517114,13336468,
 52517114,13351915,
 52531290,13351915,
 52531290,13336468,
 
 52525323,13342138,
 52526454,13343613,
 52529140,13343564,
 52529427,13343500,
 52529480,13343488,
 52527906,13339446,
 52526805,13336927,
 52526490,13336500,
 52525323,13342138,

 52520744,13348004,
 52524042,13351669,
 52527237,13351401,
 52523859,13346313,
 52523828,13346276,
 52520744,13348004];

and after that, I've added the Way to an ArrayWayOverlay to draw the polygon with holes on the map:

//wayOverlay is of type ArrayWayOverlay

wayOverlay.addWay(new OverlayWay(pointList, wayDefaultPaintFill,
                wayDefaultPaintOutline));

unfortunatly, I got very unexpected results. See the attached files. I think there is still a bug somewhere, or am I calling the wrong method?

Looking foward to your answer!

Inessa


clusterWithHoles_BUG1.png
clusterWithHoles_BUG2.png

mueh...@inf.fu-berlin.de

okunmadı,
12 Haz 2011 06:43:0512.06.2011
alıcı mapsfo...@googlegroups.com, Inessa Seifert
Hallo Inessa,

it was my mistake, i apologize. When i did the previous adjustments, i
must have been really tired. :-/

In order to draw multi-polygons correctly, the involved polygons must be
distinguishable. My first idea to put the polygon coordinates into one
big array was therefore stupid, as the borders between the different
polygons get completely lost.

Therefore i have now made a real change to the OverlayWay class which
solves the problem once and for all. The way data is now handled as a
multidimensional array. Each polygon is stored as a separate array. So
my example from the previous mail must now look like this:
[[a1, b1, c1, a1], [a2, b2, c2, a2]]

If only one polygon or a simple line should be drawn, just write:
[[a1, b1, c1]]

For this the API had to be modified a little bit. I marked all outdated
constructors and methods as deprecated, so that developers will notice
the change. Everything was committed with revision r1139. I tested the
implementation with your given multi-polygon coordinates and now
everything is displayed correctly, as the attached screenshot proves.

Thank you again for reporting the issue and please let me know in case
you find more bugs.

Best regards,
Thilo

multipolygon.png
signature.asc
Tümünü yanıtla
Yazarı yanıtla
Yönlendir
0 yeni ileti