0

我正在使用 JGraphModelAdapter 将 Jgraph 转换为 JGrapht。它工作正常,我的顶点应该显示在 gui 上。

在 GUI 上编辑顶点的位置时,我得到了一些基本代码可以使用。(见下文)

private void positionVertices() {
    for (MapLocation aVertex : this.graphContents.vertexSet()) {
        double xPostion = (?);
        double yPostion = (?);
        this.positionAVertex(aVertex, xPostion, yPostion);
    }
}

private void positionAVertex(Object vertex, double x, double y) {
    DefaultGraphCell vertexDisplayCell = this.theModelAdapter
            .getVertexCell(vertex);
    AttributeMap cellAttributes = vertexDisplayCell.getAttributes();

    Rectangle2D bounds = GraphConstants.getBounds(cellAttributes);
    Rectangle2D newBounds = new Rectangle2D.Double(x, y, bounds.getWidth(),
            bounds.getHeight());

    GraphConstants.setBounds(cellAttributes, newBounds);

    HashMap<DefaultGraphCell, AttributeMap> cellAttributeMap = new HashMap<>();
    cellAttributeMap.put(vertexDisplayCell, cellAttributes);
    this.theModelAdapter.edit(cellAttributeMap, null, null, null);
}

每个 MapLocation(Vertex) 对象代表美国一个地方的邮政编码,它可以访问准确的纬度和经度获取器。使用它们,我应该能够将顶点定位在我的 gui 上成比例的真实位置。但是,我很难确定哪种公式(用(?)表示)在这种情况下会很好地工作。

框架设置为 MAXIMIZED_BOTH,但必须适用于任何显示器尺寸。

感谢您提前提供任何帮助。

4

2 回答 2

1

根据您的评论,我将做出以下假设。

  1. 您只会显示 48 个相邻的州,即没有阿拉斯加或夏威夷。
  2. 您不需要球面三角法所具有的精度 - 将北美视为一个扁平矩形就足够了。
  3. 您的纬度以北度数的正数给出。
  4. 您的经度以西度数的正数给出(您可能想检查一下 - 我希望这适用于仅限于美国的数据,尽管国际上常见的用法是东度为正,西度为负)。
  5. 您要显示的区域的边界是西 125 度和 65 度,北纬 50 度和 25 度。
  6. 屏幕上绘制地图的区域从(left, top)(left + width, top + height)

鉴于这些假设,以下是如何将longitude和转换latitude(x,y).

x = left + width * ( 125 - longitude ) / 60;
y = top + height * ( 50 - latitude ) / 25;

请注意,如果您的经度实际上是西度数的负数,您可以在表达式中-替换为。+x

于 2013-11-19T08:09:04.007 回答
0

这是有效的代码

 double xPostion = (124 - Math.abs(aVertex.getLongitude()));
        xPostion = xPostion / 57;           
        xPostion = xPostion * this.myWidth;
 double yPostion = 49 - aVertex.getLatitude();
        yPostion = yPostion / 25;
        yPostion = yPostion * this.myHeight ;

57 是与美国大陆最东部和最西部的经度差。

25 是美国大陆最北端和最南端的纬度差

124是美国最西部大陆的经度。

49是美国大陆最北端的纬度。

于 2013-11-21T00:07:45.107 回答