Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javafx 使用ArcGIS Java SDK绘制圆形/矩形图形_Javafx_Drawing_Desktop Application_Arcgis Runtime - Fatal编程技术网

Javafx 使用ArcGIS Java SDK绘制圆形/矩形图形

Javafx 使用ArcGIS Java SDK绘制圆形/矩形图形,javafx,drawing,desktop-application,arcgis-runtime,Javafx,Drawing,Desktop Application,Arcgis Runtime,因此,我一直在使用ArcGIS Java SDK 100.6.0开发一个地图相关的桌面应用程序(JavaFX)。我想在地图上画一些形状并保存它们。我看过这些文档,据我所知,它们提供了一个用于在地图上绘制的SketchEditor类。类对象允许我在地图上绘制手绘、多段线和多边形。我的应用程序需要一个完整的绘图功能来绘制各种形状。这门课不允许我画正方形、长方形、圆形。我的问题是如何在mapview上绘制这些形状。除了SketchEditor的可用形状之外,有没有人想到过要绘制形状 编辑:我觉得我的问

因此,我一直在使用ArcGIS Java SDK 100.6.0开发一个地图相关的桌面应用程序(JavaFX)。我想在地图上画一些形状并保存它们。我看过这些文档,据我所知,它们提供了一个用于在地图上绘制的
SketchEditor
类。类对象允许我在地图上绘制手绘、多段线和多边形。我的应用程序需要一个完整的绘图功能来绘制各种形状。这门课不允许我画正方形、长方形、圆形。我的问题是如何在mapview上绘制这些形状。除了
SketchEditor
的可用形状之外,有没有人想到过要绘制形状

编辑:我觉得我的问题不够清楚。我只想分享我的应用程序需要什么以及我可以实际实现什么:

现在,我从以下链接找到了circle的解决方法:


现在剩下的形状是矩形/正方形。我希望有人能分享他们是如何用Java解决这个问题的。

听起来你想创建图形叠加。正方形、矩形、圆=多边形。但是,您可以创建将方形或圆形标记符号添加为点的选项,然后允许用户缩放符号以使其变大或变小


听起来您想创建图形覆盖。正方形、矩形、圆=多边形。但是,您可以创建将方形或圆形标记符号添加为点的选项,然后允许用户缩放符号以使其变大或变小


我试图找到解决方法来绘制那些不受支持的形状。结果发现,通过使用多边形几何体,并给出正确的点,我可以创建这些形状(圆形、方形、矩形)。下面是代码片段,它显示了我如何绘制这些形状(返回形状的图形对象的方法):

圆圈

public static Graphic drawFullCircle(Point centerPoint, double radius, int borderColor) {
    int ptCount = 240;
    double slice = 2 * Math.PI / ptCount;
    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    for (int i = 0; i <= ptCount; i++) {
        double rad = slice * i;
        double px = centerPoint.getX() + radius * Math.cos(rad);
        double py = centerPoint.getY() + radius * Math.sin(rad);
        pc.add(new Point(px, py));
    }
    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    Graphic g = new Graphic(poly, sfs);
    return g;
}
public static Graphic drawRectangle(Point p1, Point p2, int borderColor) {
    Envelope envelope = new Envelope(p1, p2); // start (p1) and end (p2) points of a diagonal
    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    pc.add(new Point(envelope.getXMin(), envelope.getYMin()));
    pc.add(new Point(envelope.getXMax(), envelope.getYMin()));
    pc.add(new Point(envelope.getXMax(), envelope.getYMax()));
    pc.add(new Point(envelope.getXMin(), envelope.getYMax()));

    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    return new Graphic(poly, sfs);
}
public static Graphic drawSquare(Point p1, Point p2, int borderColor) {
    Envelope rectEnvelope = new Envelope(p1, p2); start (p1) and end (p2) points of a diagonal

    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    // these conditions make sure that the square is created from the start point and not from any other point.
    if(rectEnvelope.getWidth() > rectEnvelope.getHeight())
    {
        if(p2.getX() > p1.getX())
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMin()+rectEnvelope.getHeight(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMin()+rectEnvelope.getHeight(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()));
        }
        else
        {
            pc.add(new Point(rectEnvelope.getXMax()-rectEnvelope.getHeight(), rectEnvelope.getYMax()-rectEnvelope.getHeight()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMax()-rectEnvelope.getHeight(), rectEnvelope.getYMax()));
        }
    }
    else
    {
        if(p2.getY() > p1.getY())
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()+rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()+rectEnvelope.getWidth()));
        }
        else
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()-rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()-rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()));
        }
    }

    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    return new Graphic(poly, sfs);
}
方形

public static Graphic drawFullCircle(Point centerPoint, double radius, int borderColor) {
    int ptCount = 240;
    double slice = 2 * Math.PI / ptCount;
    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    for (int i = 0; i <= ptCount; i++) {
        double rad = slice * i;
        double px = centerPoint.getX() + radius * Math.cos(rad);
        double py = centerPoint.getY() + radius * Math.sin(rad);
        pc.add(new Point(px, py));
    }
    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    Graphic g = new Graphic(poly, sfs);
    return g;
}
public static Graphic drawRectangle(Point p1, Point p2, int borderColor) {
    Envelope envelope = new Envelope(p1, p2); // start (p1) and end (p2) points of a diagonal
    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    pc.add(new Point(envelope.getXMin(), envelope.getYMin()));
    pc.add(new Point(envelope.getXMax(), envelope.getYMin()));
    pc.add(new Point(envelope.getXMax(), envelope.getYMax()));
    pc.add(new Point(envelope.getXMin(), envelope.getYMax()));

    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    return new Graphic(poly, sfs);
}
public static Graphic drawSquare(Point p1, Point p2, int borderColor) {
    Envelope rectEnvelope = new Envelope(p1, p2); start (p1) and end (p2) points of a diagonal

    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    // these conditions make sure that the square is created from the start point and not from any other point.
    if(rectEnvelope.getWidth() > rectEnvelope.getHeight())
    {
        if(p2.getX() > p1.getX())
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMin()+rectEnvelope.getHeight(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMin()+rectEnvelope.getHeight(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()));
        }
        else
        {
            pc.add(new Point(rectEnvelope.getXMax()-rectEnvelope.getHeight(), rectEnvelope.getYMax()-rectEnvelope.getHeight()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMax()-rectEnvelope.getHeight(), rectEnvelope.getYMax()));
        }
    }
    else
    {
        if(p2.getY() > p1.getY())
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()+rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()+rectEnvelope.getWidth()));
        }
        else
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()-rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()-rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()));
        }
    }

    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    return new Graphic(poly, sfs);
}

这可能包含未优化的代码逻辑,但这就是我们目前使用ArcGIS Java SDK 100.6.0的全部内容。任何编辑和建议都将不胜感激。

我试图找到解决方法来绘制那些不受支持的形状。结果发现,通过使用多边形几何体,并给出正确的点,我可以创建这些形状(圆形、方形、矩形)。下面是代码片段,它显示了我如何绘制这些形状(返回形状的图形对象的方法):

圆圈

public static Graphic drawFullCircle(Point centerPoint, double radius, int borderColor) {
    int ptCount = 240;
    double slice = 2 * Math.PI / ptCount;
    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    for (int i = 0; i <= ptCount; i++) {
        double rad = slice * i;
        double px = centerPoint.getX() + radius * Math.cos(rad);
        double py = centerPoint.getY() + radius * Math.sin(rad);
        pc.add(new Point(px, py));
    }
    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    Graphic g = new Graphic(poly, sfs);
    return g;
}
public static Graphic drawRectangle(Point p1, Point p2, int borderColor) {
    Envelope envelope = new Envelope(p1, p2); // start (p1) and end (p2) points of a diagonal
    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    pc.add(new Point(envelope.getXMin(), envelope.getYMin()));
    pc.add(new Point(envelope.getXMax(), envelope.getYMin()));
    pc.add(new Point(envelope.getXMax(), envelope.getYMax()));
    pc.add(new Point(envelope.getXMin(), envelope.getYMax()));

    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    return new Graphic(poly, sfs);
}
public static Graphic drawSquare(Point p1, Point p2, int borderColor) {
    Envelope rectEnvelope = new Envelope(p1, p2); start (p1) and end (p2) points of a diagonal

    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    // these conditions make sure that the square is created from the start point and not from any other point.
    if(rectEnvelope.getWidth() > rectEnvelope.getHeight())
    {
        if(p2.getX() > p1.getX())
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMin()+rectEnvelope.getHeight(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMin()+rectEnvelope.getHeight(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()));
        }
        else
        {
            pc.add(new Point(rectEnvelope.getXMax()-rectEnvelope.getHeight(), rectEnvelope.getYMax()-rectEnvelope.getHeight()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMax()-rectEnvelope.getHeight(), rectEnvelope.getYMax()));
        }
    }
    else
    {
        if(p2.getY() > p1.getY())
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()+rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()+rectEnvelope.getWidth()));
        }
        else
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()-rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()-rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()));
        }
    }

    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    return new Graphic(poly, sfs);
}
方形

public static Graphic drawFullCircle(Point centerPoint, double radius, int borderColor) {
    int ptCount = 240;
    double slice = 2 * Math.PI / ptCount;
    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    for (int i = 0; i <= ptCount; i++) {
        double rad = slice * i;
        double px = centerPoint.getX() + radius * Math.cos(rad);
        double py = centerPoint.getY() + radius * Math.sin(rad);
        pc.add(new Point(px, py));
    }
    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    Graphic g = new Graphic(poly, sfs);
    return g;
}
public static Graphic drawRectangle(Point p1, Point p2, int borderColor) {
    Envelope envelope = new Envelope(p1, p2); // start (p1) and end (p2) points of a diagonal
    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    pc.add(new Point(envelope.getXMin(), envelope.getYMin()));
    pc.add(new Point(envelope.getXMax(), envelope.getYMin()));
    pc.add(new Point(envelope.getXMax(), envelope.getYMax()));
    pc.add(new Point(envelope.getXMin(), envelope.getYMax()));

    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    return new Graphic(poly, sfs);
}
public static Graphic drawSquare(Point p1, Point p2, int borderColor) {
    Envelope rectEnvelope = new Envelope(p1, p2); start (p1) and end (p2) points of a diagonal

    PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
    // these conditions make sure that the square is created from the start point and not from any other point.
    if(rectEnvelope.getWidth() > rectEnvelope.getHeight())
    {
        if(p2.getX() > p1.getX())
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMin()+rectEnvelope.getHeight(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMin()+rectEnvelope.getHeight(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()));
        }
        else
        {
            pc.add(new Point(rectEnvelope.getXMax()-rectEnvelope.getHeight(), rectEnvelope.getYMax()-rectEnvelope.getHeight()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMax()-rectEnvelope.getHeight(), rectEnvelope.getYMax()));
        }
    }
    else
    {
        if(p2.getY() > p1.getY())
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMin()+rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMin()+rectEnvelope.getWidth()));
        }
        else
        {
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()-rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()-rectEnvelope.getWidth()));
            pc.add(new Point(rectEnvelope.getXMax(), rectEnvelope.getYMax()));
            pc.add(new Point(rectEnvelope.getXMin(), rectEnvelope.getYMax()));
        }
    }

    Polygon poly = new Polygon(new PartCollection(pc));
    SimpleFillSymbol sfs = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x00FFFFFF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, borderColor, 1.5f));
    return new Graphic(poly, sfs);
}

这可能包含未优化的代码逻辑,但这就是我们目前使用ArcGIS Java SDK 100.6.0的全部内容。任何编辑和建议都将不胜感激。

这是我可以采取的一种方法。但是,我不确定是否可以使用标记符号作为形状,是否可以对内部形状和轮廓进行不同的着色。谢谢你的回答。这是我可以采取的一种方法。但是,我不确定是否可以使用标记符号作为形状,是否可以对内部形状和轮廓进行不同的着色。谢谢你的回答。