0

I downloaded Arcgis sample mmpk file and even I made a mmpk myself.
In both files I have 1 map(checked by debug) but when I try load the map (with codes in Esri guide page) it returns null for map.
Good to say that I can show online map in my map view and android studio shows no warning or error.

    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);

code and file from main site

            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() {

this if gets 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();

As I told part below works correctly

 //        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();
        }

    }
4

2 回答 2

0

if the line

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

is returning false, then the mobile map package is not loaded and won't contain any maps.

In your dealWithLoadFailure() function you can retrieve the load error:

mobileMapPackage.getLoadError()

and see what it is. It should tell you what the error causing the load failure is.

于 2017-09-18T20:46:36.397 回答
0

One of my friends tried this way but didn't got any result just like me.
So he changed the official guide code to this and got well response. I think he got code from Internet , so I don't know about it's copyright permission.

 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();
    }
}
于 2017-10-19T23:59:35.600 回答