首页 / 浏览问题 / 组件GIS / 问题详情
iObjectsjava如何给布局模版添加指北针类
288EXP 2026年03月26日

目前在iObjectsjava里使用以下方法取得工作空间里的布局模版layout,然后遍历里面的内容,调整地图显示位置,文字显示的内容,最后导出成pdf。

现在我想根据参数在这个模版上添加一个指北针类,放在地图的左上或者右上。请问代码上应该怎么添加:

String layoutXML = globalWorkspace.getLayouts().getLayoutXML(pdfSizeStr);
MapLayout mapLayout = new MapLayout(globalWorkspace);
mapLayout.fromXML(layoutXML)
LayoutElements layoutElements = mapLayout.getElements();

while (!layoutElements.isEOF()) {
    Geometry geom = layoutElements.getGeometry();
    if (geom.getType().toString().equals("GEOMAP")) {

我尝试使用以下代码添加,但运行后只有地图可以正常显示,其他文字都恢复成了默认文字,指北针也没有出现:

try{
    GeoNorthArrow geoNorthArrow = new GeoNorthArrow();
    geoNorthArrow.setBindingGeoMapID(geoMap.getID());
    geoNorthArrow.setHeight(10);
    geoNorthArrow.setHeight(10);
    layoutElements.addNew(geoNorthArrow);
}
catch(Exception e){
    System.out.println(e.getMessage());
}

目前把添加指北针的代码移动到遍历外面并进行了一定的修改,遍历的文字修改可以正常显示了但依然无法显示指北针,并且没有报错:

if(houiSymbolFlg){
    try{
       System.out.println(geoMaoId);
       System.out.println(geoMapRectangle2D);
       GeoNorthArrow geoNorthArrow = new GeoNorthArrow();
       geoNorthArrow.setBindingGeoMapID(geoMaoId);
       geoNorthArrow.setHeight(10);
       geoNorthArrow.setHeight(10);
                 if (geoMapRectangle2D != null) {
                     geoNorthArrow.setBounds(new Rectangle2D(new Point2D(geoMapRectangle2D.rightTop), 10, 10));
          layoutElements.addNew(geoNorthArrow);
                 }
       System.out.println(geoNorthArrow);
    }
    catch(Exception e){
       System.out.println(e.getMessage());
    }
}

1个回答

您好,代码中暂时没发现问题,初步怀疑是指北针样式没设置对

可以试试GeoNorthArrow(NorthArrowStyleType styleType, Rectangle2D bounds, double rotation)这个构造方法设置一个默认的较大的指北针试试呢

希望能帮到您
1,570EXP 2026年03月26日
...