首页 / 浏览问题 / 移动GIS / 问题详情
android 加载iserver 地图显示空白
Lsk
11EXP 2022年10月13日
问题是 展示地图页面 只有空白和左下角的supermap水印
代码如下
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.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;

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.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 void openMap() {
        Workspace wokspace = new Workspace();
        MapView m_mapView = (MapView) findViewById(R.id.Map_view);
        MapControl m_mapControl = m_mapView.getMapControl();
        m_mapControl.getMap().setWorkspace(wokspace);

        DatasourceConnectionInfo dsInfo = new DatasourceConnectionInfo();
        dsInfo.setServer("http://support.supermap.com.cn:8090/iserver/services/map-china400/rest/maps/China");
        dsInfo.setEngineType(EngineType.Rest);
        Datasource datasource = wokspace.getDatasources().open(dsInfo);
        if (datasource != null) {
            Dataset dataset = datasource.getDatasets().get(0);
            m_mapControl.getMap().getLayers().add(dataset, true);
            m_mapControl.getMap().refresh();
            Datasets datasets = datasource.getDatasets();
            SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
                    WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

            Map m_Map = m_mapControl.getMap();
            m_Map.setWorkspace(wokspace);

            m_Map.getLayers().add(datasets.get(0), true);

        } else {
            Toast.makeText(getApplicationContext(), "为空", Toast.LENGTH_LONG).show();
        }
    }




}

debugger 控制台信息:

D/: HostConnection::get() New Host Connection established 0xd2ec9960, tid 15405
D/: HostConnection::get() New Host Connection established 0xcc988ed0, tid 15407
I/Supermap: true
I/Supermap: true
I/art: Do partial code cache collection, code=61KB, data=47KB
I/art: After code cache collection, code=60KB, data=46KB
    Increasing code cache capacity to 256KB
D/: HostConnection::get() New Host Connection established 0xcc989ef0, tid 15466
D/: HostConnection::get() New Host Connection established 0xadafead0, tid 15467
D/: HostConnection::get() New Host Connection established 0xcc989fb0, tid 15469
D/: HostConnection::get() New Host Connection established 0xadafeb90, tid 15468
D/: HostConnection::get() New Host Connection established 0xcc98a5b0, tid 15470
E/libEGL: eglMakeCurrent:791 error 3006 (EGL_BAD_CONTEXT)
E/libEGL: eglMakeCurrent:791 error 3006 (EGL_BAD_CONTEXT)

1个回答

您好,看您的代码中没有设置数据源连接信息的别名,应该使用DatasourceConnectionInfo.setAlias设置数据源别名,注意别名不能重复
3,685EXP 2022年10月13日
请问这个数据源别名设置根据是什么,如何设置,第一次接触超图,请指教

我添加了如下代码依然显示空白

dsInfo.setAlias("ChinaRest");
您好,这份工程这边加载没问题的,您可以看一下呢

链接:https://pan.baidu.com/s/109uStIDS84e_vmtUINNWow?pwd=8754
提取码:8754
...