//本地数据地址
private String workspacePath = sdcard + "/SuperMap/data/test/World.smwu";
// 本地数据的场景名称
private String sceneName = "scene";
// 工作空间相关类
private WorkspaceConnectionInfo info;
private WorkspaceType workspaceTypetemp = null;
private boolean isOpenSceneSuccess = false;
// 三维场景
private Scene scene;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_map://二维
setMapLayout();
break;
case R.id.btn_scene://三维
setSceneLayout();
openLocalScene();
break;
case R.id.btn_linkage://二三维
setLayout();
openLocalScene();
break;
}
}
/**
* @author:Supermap
* @注释 :打开一个本地场景数据
*/
private void openLocalScene() {
//新建一个工作空间对象
if (workspace == null) {
workspace = new Workspace();
}
//根据工作空间类型,设置服务路径和类型信息
if (info == null) {
info = new WorkspaceConnectionInfo();
}
workspaceTypetemp = WorkspaceType.SMWU;
info.setServer(workspacePath);
info.setType(workspaceTypetemp);
scene = sceneControl.getScene();
//场景关联工作空间
if (workspace.open(info)) {
scene.setWorkspace(workspace);
}
//打开场景
isOpenSceneSuccess = scene.open(sceneName);
}
/**
* mapView需要设置一个宽度
*/
private void setSceneLayout() {
//获取手机分辨率
DisplayMetrics dp = new DisplayMetrics();
//将当前窗口的一些信息放在DisplayMetrics
//getDefaultDisplay()将取得的宽高维度存放于DisplayMetrics对象中
getWindowManager().getDefaultDisplay().getMetrics(dp);
//设备的 宽度
width = dp.widthPixels;
//设备的高度
height = dp.heightPixels;
double y = 1;
double x = (dp.widthPixels - dp2px(50));
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) rl_map.getLayoutParams();
params.width = (int) y;
params.height = (int) height;
rl_map.setLayoutParams(params);
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) rl_scene.getLayoutParams();
params1.height = (int) height;
params1.width = (int) x;
rl_scene.setLayoutParams(params1);
}
private void setLayout() {
DisplayMetrics dp = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dp);
width = dp.widthPixels;
height = dp.heightPixels;
double x = (dp.widthPixels - dp2px(50)) / 2;
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) rl_map.getLayoutParams();
params.width = (int) x;
params.height = (int) height;
rl_map.setLayoutParams(params);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams((int) x, (int) height);
params1.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
rl_scene.setLayoutParams(params1);
}
这是代码这边 这是因为什么呢 也没报错什么的 联动的时候二维不显示了 三维显示一下 然后直接闪退了就
代码这边全粘贴的话超过8000个字符了