public class MainActivity extends Activity {
private MapControl m_mapcontrol = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Environment.initialization(this);
String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
//设置一些系统需要用到的路径
Environment.setLicensePath(rootPath + "/SuperMap/license/");
Environment.setTemporaryPath(rootPath + "/SuperMap/temp/");
Environment.setWebCacheDirectory(rootPath + "/SuperMap/WebCatch");
//如果机器中默认不包括需要显示的字体,可以把相关字体文件放在参数所代表的路径中。
//例如,如果需要显示阿拉伯文字(若机器中原先不包括相关字体文件),可以把需要的字体文件放在参数所代表的路径中。
Environment.setFontsPath(rootPath + "/SuperMap/fonts/");
setContentView(R.layout.activity_main);
MapView m_mapView = findViewById(R.id.Map_view);
m_mapcontrol = m_mapView.getMapControl();
test(rootPath);
ZoomControls m_zoom = findViewById(R.id.zoomControls1);
m_zoom.setIsZoomInEnabled(true);
m_zoom.setIsZoomOutEnabled(true);
//放大按钮
m_zoom.setOnZoomInClickListener(new View.OnClickListener() {
public void onClick(View v) {
m_mapcontrol.getMap().zoom(2);
m_mapcontrol.getMap().refresh();
}
});
//缩小按钮
m_zoom.setOnZoomOutClickListener(new View.OnClickListener(){
public void onClick(View v) {
m_mapcontrol.getMap().zoom(0.5);
m_mapcontrol.getMap().refresh();
}
});
}
private void test(String idcard){
//将地图显示控件和工作空间关联
Workspace mWorkspace = new Workspace();
// MapControl mMapControl = ((MapView) findViewById(R.id.mapView)).getMapControl();
Map mMap = m_mapcontrol.getMap(); //获取在地图控件中显示的地图对象
mMap.setWorkspace(mWorkspace); //设置当前地图所关联的工作空间
//以数据源的方式打开MVT数据
DatasourceConnectionInfo dsInfo = new DatasourceConnectionInfo();
dsInfo.setServer(idcard + "/Map/styles/style.json");
dsInfo.setEngineType(EngineType.MVTCache);
dsInfo.setAlias("MVT");
Datasource ds = mWorkspace.getDatasources().open(dsInfo);
if (ds == null) {
return;
}
//地图显示范围可在iDesktop中,通过地图属性查看
mMap.getLayers().add(ds.getDatasets().get(0), true);
// mMap.setScale(1/144447.92746805);
Point2D point2D=new Point2D(113.66,22.72);
Point2D point2D2=new Point2D(113.77,22.87);
Rectangle2D rectangle2D=new Rectangle2D(point2D,point2D2);
mMap.setViewBounds(new Rectangle2D(rectangle2D));
Log.e("MainActivity", "left: " + ds.getDatasets().get(0).getBounds().getLeft() + ", right: " + ds.getDatasets().get(0).getBounds().getRight());
Log.i("MainActivity",ds.getDatasets().getCount()+"");
mMap.refresh();
}
}
1.在iDesktop软件切图时设置比例尺是从 13级级开始切的
2.坐标系 WGS84(4326)
3.在代码中加上了中心点
Point2D point2D=new Point2D(113.66,22.72);
Point2D point2D2=new Point2D(113.77,22.87);
Rectangle2D rectangle2D=new Rectangle2D(point2D,point2D2);
mMap.setViewBounds(new Rectangle2D(rectangle2D));
使用的imobile for Android产品包版本号 supermap-imobile-10.0.1-189-android-zip-chs_(精简绿色包)