简体   繁体   中英

How to draw a polygon with javafx, with a multidimensional array as parameter

I'm trying to draw maps from a series of coordinates which are multidimensional arrays with javafx Polygons.

It works perfectly with only one simple array:

Polygon polygon = new Polygon();
polygon.getPoints().addAll(new Double[] { 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0 });

But not with an array from arrays. The coordinates look for example like this:

http://polygons.openstreetmap.fr/get_geojson.py?id=62428&params=0

I've been researching all morning but haven't found a useful solution. Any help would be really appreciated

The JavaFX polygon only supports a single contour, so for multiple contours you need to create an array of polygons and loop over it, for example:

ArrayList<Polygon> polygons = new ArrrayList<Polygon>;
...
for (double [] region : regionArray) {
    Polygon polygon = new Polygon();
    polygon.getPoints().addAll(region);
    polygons.add(polygon);
 }

The tricky part will be handling polygons inside other polygons because these should probably appear as 'holes'. But I think that JavaFX can take care of that if you use the right settings for drawing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM