我是将工作空间的文件中新增一个地图的图层,执行如下的方法之后,能够再idesktop看到添加成功,但是 通过idesktop打开之后,图层没有数据,如下图,请问一下是什么原因呢?
public void layersTestTwo() {
// 返回 captial、world、ocean 数据集
Workspace workspace = new Workspace();
WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo();
workspaceConnectionInfo.setServer("D:/supermap/软件安装/supermap-iobjectsjava-9.0.0-15320-63946-linux64-tar.gz-chs/SampleData/World/World.smwu");
workspaceConnectionInfo.setType(WorkspaceType.SMWU);
workspace.open(workspaceConnectionInfo);
Datasource datasource = workspace.getDatasources().get(0);
Dataset dataset0 = datasource.getDatasets().get("Capital");
Dataset dataset1 = datasource.getDatasets().get("World");
Dataset dataset2 = datasource.getDatasets().get("Ocean");
Dataset dataset3 = datasource.getDatasets().get("Lakes");
// 打开地图
Map map = new Map(workspace);
int mapsCount = workspace.getMaps().getCount();
System.out.println("mapsCount==>"+mapsCount);
int mapIndex = 0;
//获取指定序号的地图的名字
// String name = workspace.getMaps().get(0);
int index = workspace.getMaps().add("Capital",map.toXML());
System.out.println("index===>"+index);
map.open(workspace.getMaps().get(index));
map.refresh();
System.out.println("mapName====>"+map.getName());
// 返回图层集合
Layers layers = map.getLayers();
// 构造 LayerSettingVector 对象并进行设置
LayerSettingVector layerSettingVector = new LayerSettingVector();
GeoStyle style = new GeoStyle();
style.setFillForeColor(java.awt.Color.lightGray);
layerSettingVector.setStyle(style);
// 对图层集合进行操作,包括删除、添加、插入、移动、清除等
layers.clear();
layers.add(dataset1, layerSettingVector, true);
layers.add(dataset0, layerSettingVector, true);
layers.add(dataset2, layerSettingVector, true);
layers.add(dataset3, layerSettingVector, true);
boolean result = workspace.getMaps().setMapXML(map.getName(),map.toXML());
System.out.println("===>"+result);
System.out.println(layers.getCount());
workspace.save();
// 释放资源
map.close();
// datasourceConnectInfo.dispose();
workspace.dispose();
}