Skip to content

Commit

Permalink
better error handling for failed geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
jclark118 committed Oct 9, 2023
1 parent 2b27197 commit c43d004
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,8 @@ private void processFeatureRow(MapFeaturesUpdateTask task, String database, Feat
}
}
} catch (Exception e) {
new Handler(Looper.getMainLooper()).post(() -> {
Toast toast = Toast.makeText(context, "Error loading geometry", Toast.LENGTH_SHORT);
toast.show();
});
// set task error
task.setErrorCount(task.getErrorCount() + 1);
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions mapcache/src/main/java/mil/nga/mapcache/MapFeaturesUpdateTask.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package mil.nga.mapcache;

import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Marker;
Expand Down Expand Up @@ -86,6 +89,11 @@ public class MapFeaturesUpdateTask implements Runnable {
*/
private boolean filter;

/**
* Keep track of any errors when displaying features on the map
*/
private int errorCount = 0;

/**
* Constructor.
*
Expand Down Expand Up @@ -265,6 +273,8 @@ private void displayFeatures(GeoPackage geoPackage, StyleCache styleCache, Strin

// Get the GeoPackage and feature DAO
String database = geoPackage.getName();
setErrorCount(0);

Map<String, FeatureDao> dataAccessObjects = model.getFeatureDaos().get(database);
if (dataAccessObjects != null) {
FeatureDao featureDao = dataAccessObjects.get(features);
Expand Down Expand Up @@ -336,8 +346,16 @@ private void displayFeatures(GeoPackage geoPackage, StyleCache styleCache, Strin
+ ", row: " + cursor.getPosition(), e);
}
}
if(getErrorCount() > 0){
new Handler(Looper.getMainLooper()).post(() -> {

Toast toast = Toast.makeText(activity, "Error loading geometry", Toast.LENGTH_SHORT);
toast.show();
});
setErrorCount(0);
}
}

}
indexer.close();

Expand All @@ -361,6 +379,8 @@ private void displayFeatures(GeoPackage geoPackage, StyleCache styleCache, Strin
private void processFeatureIndexResults(FeatureIndexResults indexResults, String database, FeatureDao featureDao,
GoogleMapShapeConverter converter, StyleCache styleCache, AtomicInteger count, final int maxFeatures, final boolean editable) {
try {
setErrorCount(0);

for (FeatureRow row : indexResults) {

if (cancelled || count.get() >= maxFeatures) {
Expand All @@ -384,6 +404,14 @@ private void processFeatureIndexResults(FeatureIndexResults indexResults, String
}
} finally {
indexResults.close();
if(getErrorCount() > 0){
new Handler(Looper.getMainLooper()).post(() -> {
Toast toast = Toast.makeText(activity, getErrorCount() + " Geometries failed to load", Toast.LENGTH_SHORT);
toast.show();
});
setErrorCount(0);

}
}
}

Expand All @@ -402,6 +430,15 @@ private void addMarkerShape(long featureId, String database, String tableName, G
model.getMarkerIds().put(marker.getId(), markerFeature);
}
}
/**
* Update the number of errors encountered while processing features
*/
public int getErrorCount() {
return errorCount;
}
public void setErrorCount(int errorCount) {
this.errorCount = errorCount;
}

@Override
public void run() {
Expand Down

0 comments on commit c43d004

Please sign in to comment.