通过WorkspaceConnectionInfo的.setServer( "/sdcard/SuperMap/SampleData/DataConversion/World.smwu")后获取
Datasource udbDatasource是可以导入的,但是我下面的代码不能导入,好像是DataSource的问题。请大佬看看。
这个代码是直接在DataConversion上面改的,原来的可以导入,我设置成天地图就不可以了。
/**
* 打开地图
*/
private void openMap() {
mWorkspace = new Workspace();
// 将地图显示控件和工作空间关联
mMapView = (MapView) findViewById(R.id.main_second_mapview);
mMapControl = mMapView.getMapControl();
mMapControl.getMap().setWorkspace(mWorkspace);
// WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
// info.setServer( "/sdcard/SuperMap/SampleData/DataConversion/World.smwu");
// info.setType(WorkspaceType.SMWU);
// mWorkspace.open(info);
//天地图
tiandidsInfo = new DatasourceConnectionInfo();
tiandidsInfo.setServer(TIANDI_URL);
tiandidsInfo.setEngineType(EngineType.OGC);
tiandidsInfo.setAlias("tiandi");
mMapControl.getMap().setMapDownLoadThreadNum(10);
tiandidsInfo.setDriver("WMTS");
tiandids = mWorkspace.getDatasources().open(tiandidsInfo);
if (tiandids != null) {
Log.d("ContentName.TAG", String.valueOf(tiandids.getDatasets().getCount()) );
for(int i = 0; i< tiandids.getDatasets().getCount(); i++)
{
Log.d("ContentName.TAG","获取的Datasets:"+ tiandids.getDatasets().get(i).getName()+ " ");
}
mMapControl.getMap().getLayers().add(tiandids.getDatasets().get(0), true);
mMapControl.getMap().viewEntire();
mMapControl.getMap().setScale(1 / 7984.375);
mMapControl.getMap().refresh();
}
}
/**
* 构造函数
*
* @param mapcontrol
*/
public ImportData(MapControl mapcontrol,Context context) {
mMapControl = mapcontrol;
this.context = context;
mInflater = LayoutInflater.from(mMapControl.getContext());
loadView();
setContentView(mContentView);
setWidth(LayoutParams.WRAP_CONTENT);
setHeight(LayoutParams.WRAP_CONTENT);
// udbDatasource = mMapControl.getMap().getWorkspace().getDatasources()
// .get("World");//可以加载kml
udbDatasource = mMapControl.getMap().getWorkspace().getDatasources()
.get("tiandi");//不可以加载
}
private void importKml(Context context){
removeLayer();
mMapControl.getMap().refresh();
try {
if (udbDatasource.getDatasets().get("mykml1") != null){
boolean d = udbDatasource.getDatasets().delete("mykml1");
}
boolean kml = DataConversion.importKML( "/sdcard/JSTI/Project/路基路面/YK0+000——YK6+700.kml",udbDatasource,"mykml2",true);
if (kml == true){
mMapControl.getMap().getLayers().add(udbDatasource.getDatasets().get(udbDatasource.getDatasets().getCount()-1),true);
// dataset = udbDatasource.getDatasets().get(
// "mykml");
// addMap();
Toast.makeText(context, "真棒,导入kml格式文件成功", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "难过,导入kml格式文件失败", Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
e.printStackTrace();
}
}