Using ArcGIS Android API,
After my MobileMapPackage loads, I want to store the inital map extents (i.e., getVisibleArea()) so that I can later allow the user the option of viewing the initial map extents.
APPROACH:
After my MobileMapPackage's getLoadStatus() returns "LOADED", I get a reference to the ArcGISMap contained therein. Next, I listen for the ArcGISMap's getLoadStatus() to return "LOADED". Finally, I ask the MapView containing the ArcGISMap for it's visible area but sometimes the following Exception is thrown:
Attempt to invoke virtual method 'com.esri.arcgisruntime.geometry.Envelope com.esri.arcgisruntime.geometry.Geometry.getExtent()' on a null object reference
Is there some other async process that I should be waiting for before inquiring about the visible area of the mMapView? Relevant snippet code below:
this.mapPackage = new MobileMapPackage(mmpkFile); // load the mobile map package asynchronously this.mapPackage.loadAsync(); // add done listener which will invoke when mobile map package has loaded this.mapPackage.addDoneLoadingListener(new Runnable() { @Override public void run() { // check load status and that the mobile map package has maps switch (MainActivity.this.mapPackage.getLoadStatus()) { case LOADING, FAILED_TO_LOAD, NOT_LOADED: // do nothing for now... break; case LOADED: if (MainActivity.this.mapPackage.getMaps().size() > 0) { // add the map from the mobile map package to the MapView ArcGISMap map = MainActivity.this.mapPackage.getMaps().get(0); MainActivity.this.arcGISMap = map; MainActivity.this.mMapView.setMap(map); MainActivity.this.arcGISMap.addDoneLoadingListener(new Runnable() { @Override public void run() { try { switch (MainActivity.this.arcGISMap.getLoadStatus()) { case LOADING, FAILED_TO_LOAD, NOT_LOADED: // do nothing for now... break; case LOADED: MainActivity.this.initialEnvelope = MainActivity.this.mMapView.getVisibleArea().getExtent(); if (initialEnvelope != null) { Log.d("LoadMobileMapPackage", "initialEnvelope: " + initialEnvelope); } break; } } catch (Exception e) { Log.e(TAG, e.getMessage()); } } }); } } } });
Did you ever find a fix or working around for this? Currently running into the same issue while creating a custom scale bar.