版本是supermap-iobjectsjava-10.2.1-20428-92245-win64-all-Bin,其他布局元素可以正常打印出来,打印出来看到geomap的边框也被加入进去了,但是geomap始终是白的。
您好,我在本机验证是布局可以正常出图GeoMap的,建议您参考一下代码,对您的代码逻辑进行调整
public static void main(String[] args) { // write your code here Workspace workspace = new Workspace(); Map map = new Map(); map.setName("testMap"); MapLayout mapLayout = new MapLayout(); DatasourceConnectionInfo connectionInfo = new DatasourceConnectionInfo(); connectionInfo.setServer("test.UDBX"); connectionInfo.setEngineType(EngineType.UDBX); map.setWorkspace(workspace); Datasource datasource = workspace.getDatasources().open(connectionInfo); Layer layer = map.getLayers().add(datasource.getDatasets().get(0), true); map.viewEntire(); workspace.getMaps().add(map.getName(), map.toXML()); mapLayout.setWorkspace(workspace); GeoMap geoMap = new GeoMap(); GeoRegion geoRegion = new GeoRegion(); Point2Ds points = new Point2Ds(); points.add(new Point2D(10, 10)); points.add(new Point2D(300, 10)); points.add(new Point2D(300, 300)); points.add(new Point2D(10, 300)); points.add(new Point2D(10, 10)); geoRegion.addPart(points); geoMap.setShape(geoRegion); geoMap.setMapName(map.getName()); geoMap.setMapViewBounds(layer.getBounds()); geoMap.setBounds(layer.getBounds()); mapLayout.getElements().addNew(geoMap); String outputFile = "test.png"; File file = new File(outputFile); if (file.exists()) { file.delete(); } mapLayout.printToFile(outputFile, PrintFileType.PNG, 96, false); Runtime runtime = Runtime.getRuntime(); try { runtime.exec("cmd /c " + file.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }
测试了下,这样是可以出图。但是更新了map的状态后,比如我筛选显示地图要素,再定位。再绑定后用更新后的地图,地图没有被更新。还是全局的状态。