首页 / 浏览问题 / 移动GIS / 问题详情
Android加载iserver显示空白
Lsk
11EXP 2022年10月14日
package com.example.supermapimobile2d;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.SensorManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;

import com.supermap.data.Dataset;
import com.supermap.data.Datasets;
import com.supermap.data.Datasource;
import com.supermap.data.DatasourceConnectionInfo;
import com.supermap.data.EngineType;
import com.supermap.data.Environment;
//import android.os.Environment;
import com.supermap.data.Workspace;
import com.supermap.data.WorkspaceConnectionInfo;
import com.supermap.data.WorkspaceType;
import com.supermap.mapping.Map;
import com.supermap.mapping.MapControl;
import com.supermap.mapping.MapView;
import com.supermap.mapping.view.LayerListView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestPermissions();
        MapControl mapControl = null;
        MapControl m_mapControl = null;
        String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
//        Environment.setLicensePath(rootPath + "/SuperMap/license/");
        Environment.setLicensePath(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+"/SuperMap/license/");
        Environment.setWebCacheDirectory(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+"/SuperMap/WebCache/");
        Environment.setTemporaryPath(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+"/SuperMap/temp/");
        Environment.initialization(this);
        setContentView(R.layout.activity_main);
        openMap();


    }
    private void requestPermissions() { //Android6.0以上设备设置动态权限
        if (Build.VERSION.SDK_INT >= 23) {
            // 检查是否拥有权限
            String[] permissions = {
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.READ_PHONE_STATE,
                    Manifest.permission.ACCESS_WIFI_STATE,
                    Manifest.permission.ACCESS_NETWORK_STATE,
                    Manifest.permission.CHANGE_WIFI_STATE,
            };
            String permission = null;
            int id = 0;
            boolean isBreak = false;
            int checkCallPhonePermission = 0;
            for (int i = 0; i < permissions.length; i++) {
                permission = permissions[i];
                checkCallPhonePermission = checkSelfPermission(permission);
                if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                    requestPermissions(permissions, id);
                    isBreak = true;
                    break;
                }
            }
        }

    }
    

    private boolean openMap() {
        Workspace m_woWorkspace = new Workspace(); // 将地图显示控件与工作空间关联
        MapView m_mapView = (MapView) findViewById(R.id.Map_view);
        MapControl m_mapControl = m_mapView.getMapControl();
        m_mapControl.getMap().setWorkspace(m_woWorkspace);
        DatasourceConnectionInfo dsInfo = new DatasourceConnectionInfo();

        dsInfo.setServer("http://192.168.4.20:8090/iserver/services/map-ChinaAyl/rest/maps/China");
        dsInfo.setEngineType(EngineType.Rest);
        dsInfo.setAlias("China");
        Datasource ds = m_woWorkspace.getDatasources().open(dsInfo);

        if(ds != null){
            m_mapControl.getMap().getLayers().add(ds.getDatasets().get(0), true);
            m_mapControl.getMap().viewEntire();
            m_mapControl.getMap().setVisibleScalesEnabled(true);
        }

        return true;
    }





}

1个回答

您好,这里看您的代码是没问题的,您把设备根目录下面的/SuperMap/data/下面的文件都删除呢
3,685EXP 2022年10月14日
你好 删除了 依然是显示空白
检查一下许可路径是否正确,许可是否可用呢
您好,路径没问题,许可也是刚申请的 依然显示空白
您好,您可以看下这份工程,这边加载没问题的

链接:https://pan.baidu.com/s/109uStIDS84e_vmtUINNWow?pwd=8754
提取码:8754
经测试发现,要添加Environment.openGLMode(false)切换为内存引擎,否则就会默认使用openGL,openGL引擎在模拟器上不存在导致绘制失败看不到地图
谢谢,解决了
...