移动地图包为地图返回null

时间:2017-09-17 12:53:42

标签: dictionary arcgis arcgis-android-api

我下载了 Arcgis 示例 mmpk 文件,甚至我自己制作了一个mmpk。
在这两个文件中,我有1个地图(通过调试检查)但是当我尝试加载地图(在 Esri 指南页面中有代码)时,它会返回 null 作为地图。
很高兴我可以在我的地图视图中显示在线地图,并且android studio显示没有警告或错误。

    import static n.k.masoud.sbmap.R.id.mapView;


    public class ActivityMain extends AppCompatActivity {
        private MapView mMapView;
        private ArcGISMap map;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mMapView = (MapView) findViewById(mapView);
  

主站点的代码和文件

            try {File mmpkFile = new File(Environment.getExternalStorageDirectory(),"devlabs-package.mmpk");
            String mmpkPath = mmpkFile.getAbsolutePath();
            final MobileMapPackage mobileMapPackage=new MobileMapPackage(mmpkPath);


  mobileMapPackage.addDoneLoadingListener(new Runnable() {
       @Override
         public void run() {
  

如果获取 false

             if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED) {
               showMessage(String.format("Number of maps = %d", mobileMapPackage.getMaps().size()));
map = mobileMapPackage.getMaps().get(0);
            } else {
               dealWithLoadFailure();
              }
           }
     });
       mobileMapPackage.loadAsync();
   }
    catch (Exception err){
      Log.e("TAG", "onCreate: "+err);
   }

          map.addDoneLoadingListener(new Runnable() {
              @Override
              public void run() {
                  if (map.getLoadStatus() == LoadStatus.LOADED) {
                     Log.e("TAG", "run: map loaded ok" );
                       // Once map is loaded, can check its properties and content
                    if (map.getBookmarks().size() > 0) {
}
                } else {
dealWithLoadFailure();
                 }
              }
            });
           map.loadAsync();
  

我告诉下面的部分正常工作

 //        for online maps
    //        ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 29.453826, 60.852134,12);

            mMapView.setMap(map);
mMapView.addLayerViewStateChangedListener(new LayerViewStateChangedListener() {
                @Override
                public void layerViewStateChanged(LayerViewStateChangedEvent layerViewStateChangedEvent) {
                    // Each layer may have more than one layer view state.
                    StringBuilder layerStatuses = new StringBuilder();
                    for (LayerViewStatus status : layerViewStateChangedEvent.getLayerViewStatus()) {
                        if (layerStatuses.length() > 0) {
                            layerStatuses.append(",");
                        } layerStatuses.append(status.name());
                    }
                    showMessage(String.format("Layer '%s' status=%s", layerViewStateChangedEvent.getLayer().getName(), layerStatuses.toString()));
                } });



        }
        @Override
        protected void onPause(){
            mMapView.pause();
            super.onPause();
        }

        @Override
        protected void onResume(){
            super.onResume();
            mMapView.resume();
        }

    }

2 个答案:

答案 0 :(得分:0)

如果该行

if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED)

返回false,然后未加载移动地图包,并且不包含任何地图。

在dealWoLoadFailure()函数中,您可以检索加载错误:

mobileMapPackage.getLoadError()

看看它是什么。它应该告诉您导致加载失败的错误是什么。

答案 1 :(得分:0)

我的一位朋友尝试过这种方式,但没有像我一样得到任何结果 因此,他将官方指南代码更改为此并获得了良好的响应。 我认为他从互联网获取代码,所以我不知道它的版权许可。

 private void setupMobileMap() {
    if (mMapView != null) {
        File mmpkFile = new File(Environment.getExternalStorageDirectory(), "devlabs-package.mmpk");
        final MobileMapPackage mapPackage = new MobileMapPackage(mmpkFile.getAbsolutePath());
        mapPackage.addDoneLoadingListener(new Runnable() {
            @Override
            public void run() {
                // Verify the file loaded and there is at least one map
                if (mapPackage.getLoadStatus() == LoadStatus.LOADED && mapPackage.getMaps().size() > 0) {
                     mMapView.setMap(mapPackage.getMaps().get(0));
                } else {
                    // Error if the mobile map package fails to load or there are no maps included in the package
                    //setupMap();
                    //Log for Error
                }
            }
        });
        mapPackage.loadAsync();
    }
}