首页 / 浏览问题 / 组件GIS / 问题详情
布局中添加地图 但是地图没有出来
33EXP 2023年10月20日
下面是我的代码 布局中添加了地图等 只出了标题和指北针

public void createLayout(Map map, Point2D center) {
        int mapId;
        MapLayout mapLayout = new MapLayout(_workspace);
        mapLayout.getPaper().setOrientation(PaperOrientation.LANDSCAPE);
        Dimension dimension = new Dimension();
        dimension.width = 2400;
        dimension.height = 1800;
        mapLayout.setImageSize(dimension);
        //设置横向页数
        mapLayout.setHorizontalPaperCount(1);
        //设置纵向页数
        mapLayout.setVerticalPaperCount(1);
        mapLayout.setCenter(centerPoint2D);
        mapLayout.ensureVisible(bounds);
        mapLayout.setViewBounds(bounds);

        //布局元素获取 下面就开始添加布局元素  比如地图 标题 图例 指北针等
        LayoutElements elements = mapLayout.getElements();
        //地图添加
        GeoRectangle geoRectangle = new GeoRectangle(center, 2400, 1800, 0);
        GeoMap geoMap = new GeoMap(map.getName(),geoRectangle);
        geoMap.setMapName(map.getName());
        geoMap.setMapCenter(centerPoint2D);
        geoMap.setGridVisible(false);
        mapLayout.getElements().addNew(geoMap);
        mapLayout.getElements().moveFirst();
        mapId = elements.getID();

        //标题设置
        TextStyle textStyle = new TextStyle();
        textStyle.setBackColor(Color.RED);
        GeoText geoText = new GeoText();
        TextPart part = new TextPart("布局出图测试", new Point2D(150, 150), 10.0);
        geoText.addPart(part);
        geoText.setTextStyle(textStyle);
        mapLayout.getElements().addNew(geoText);

        //图例添加

        //指北针
        GeoNorthArrow northArrow = new GeoNorthArrow(
                NorthArrowStyleType.EIGHTDIRECTION, new Rectangle2D(
                new Point2D(140, 140), new Size2D(35, 35)), 0);
        northArrow.setBindingGeoMapID(mapId);
        mapLayout.getElements().addNew(northArrow);
        mapLayout.zoomToPaper();
        mapLayout.refresh();
        mapLayout.outputLayoutToJPG(uploadDirectory);
    }
请问一下大佬怎么解决我这个不能把地图加载到布局重的问题
另外我workspace.save之后 布局没有保存进去

1个回答

您好,您的问题我已关注到,

这里需要了解一下您使用的组件版本号(您可查看 com.supermap.data.Version)
280EXP 2023年10月20日
上述代码中的map 在添加图层的时候已经设置过这个bounds了

您好,

如果您需要修改已被添加到布局的地图显示内容范围,您需要

1.激活地图:

m_mapLayoutControl.setActiveGeoMapID(mapId);

2.从布局组件获取地图对象

Map map = m_mapLayoutControl.getActiveMap();

3.再设置地图的bounds

您可以理解为:布局中添加地图时,在布局对象中系统维护了一个地图对象。 和您代码中的map不是同一对象。

我这个是我工作空间中保存的地图
我设置了mapLayout的中心点  但是没起作用是为啥
您好,

看起来您涉及多个问题,您可通过邮件发送您的联系方式给我,我为您联线解决,我的邮箱是 zhouyingping@supermap.com
...