简体   繁体   English

如何使用javafx以多维数组为参数绘制多边形

[英]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. 我正在尝试从一系列坐标绘制地图,这些坐标是使用javafx多边形的多维数组。

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 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: JavaFX多边形仅支持一个轮廓,因此对于多个轮廓,您需要创建一个多边形数组并在其上循环,例如:

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. 但是我认为,如果使用正确的设置进行绘制,JavaFX可以解决这一问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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