我的操作步骤是这样的,代码如下:(可是mLayer一直报空指针,mLayer我也声明了),数据元素通过isever链接获取的,地图能正常显示,就是画不了线,有点郁闷。。。
public void openMap(final DatasourceConnectionInfo dtsinfo){
new Thread(new Runnable() {
@Override
public void run() {
//在打开新的数据源前将原来的地图和数据集源关闭
mapControl.getMap().close();
if(workspace.getDatasources().getCount()>0){
workspace.getDatasources().close(0);
}
datasource = workspace.getDatasources().open(dtsinfo);
if (datasource!=null) {
Dataset dataset = datasource.getDatasets().get(0);
mapControl.getMap().getLayers().add(dataset, true);
mapControl.getMap().setScale(0.0002);//缩放级别
mapControl.getMap().setCenter(new Point2D(12841478.7054060008,3358417.1148373000));//地图中心点靖安县市政府~
mapControl.getMap().refresh();
mapControl.setAction(Action.CREATEPOLYLINE);
mLayer=mapControl.getMap().getLayers().get("Line@dataedit");
if(mLayer==null){
Log.e("为空","---");
return;
}
addPoint();
}
}
}).start();
}
private void addPoint(){
DatasetVector dtLine= (DatasetVector) mLayer.getDataset();
if(dtLine!=null){
Recordset recLine=dtLine.getRecordset(false, CursorType.DYNAMIC);
Point2Ds point2Ds=new Point2Ds();
point2Ds.add(new Point2D(12841478,13841478));
point2Ds.add(new Point2D(144841478,12841478));
point2Ds.add(new Point2D(13841478,12841478));
GeoLine geoLine=new GeoLine(point2Ds);
boolean isAdd=recLine.addNew(geoLine);
if(isAdd){
recLine.update();
mapControl.getMap().setViewBounds(recLine.getBounds());
mapControl.getMap().refresh();
}
recLine.dispose();
}
}