Mapsforge: catch unexpected errors (#942)

This commit is contained in:
Emux 2022-07-29 15:32:58 +03:00 committed by GitHub
parent f570105920
commit d89a402375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 38 deletions

View File

@ -31,6 +31,7 @@ import org.oscim.layers.tile.MapTile;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.tiling.ITileDataSink;
import org.oscim.tiling.ITileDataSource;
import org.oscim.tiling.QueryResult;
import org.oscim.tiling.TileDataSink;
import org.oscim.tiling.source.mapfile.header.SubFileParameter;
import org.oscim.utils.Parameters;
@ -46,11 +47,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.oscim.core.GeometryBuffer.GeometryType.LINE;
import static org.oscim.core.GeometryBuffer.GeometryType.POLY;
import static org.oscim.tiling.QueryResult.FAILED;
import static org.oscim.tiling.QueryResult.SUCCESS;
/**
* A class for reading binary map files.
*
@ -85,7 +81,7 @@ public class MapDatabase implements ITileDataSource {
*/
private static final String INVALID_FIRST_WAY_OFFSET = "invalid first way offset: ";
static final Logger log = LoggerFactory.getLogger(MapDatabase.class);
private static final Logger log = LoggerFactory.getLogger(MapDatabase.class);
/**
* Bitmask for the optional POI feature "elevation".
@ -257,16 +253,15 @@ public class MapDatabase implements ITileDataSource {
@Override
public void query(MapTile tile, ITileDataSink sink) {
if (mTileSource.fileHeader == null) {
sink.completed(FAILED);
return;
}
if (mIntBuffer == null)
mIntBuffer = new int[Short.MAX_VALUE * 2];
try {
if (mTileSource.fileHeader == null) {
sink.completed(QueryResult.FAILED);
return;
}
if (mIntBuffer == null)
mIntBuffer = new int[Short.MAX_VALUE * 2];
mTileProjection.setTile(tile);
//mTile = tile;
@ -303,7 +298,7 @@ public class MapDatabase implements ITileDataSource {
log.warn("no sub-file for zoom level: "
+ queryParameters.queryZoomLevel);
sink.completed(FAILED);
sink.completed(QueryResult.FAILED);
return;
}
@ -313,13 +308,13 @@ public class MapDatabase implements ITileDataSource {
processBlocks(sink, queryParameters, subFileParameter, tile.getBoundingBox(), Selector.ALL, new MapReadResult());
else
processBlocks(sink, queryParameters, subFileParameter);
} catch (IOException e) {
log.error(e.getMessage());
sink.completed(FAILED);
} catch (Throwable t) {
log.error(t.getMessage(), t);
sink.completed(QueryResult.FAILED);
return;
}
sink.completed(SUCCESS);
sink.completed(QueryResult.SUCCESS);
}
@Override
@ -826,7 +821,7 @@ public class MapDatabase implements ITileDataSource {
}
if (e.type == GeometryType.NONE)
e.type = line ? LINE : POLY;
e.type = line ? GeometryType.LINE : GeometryType.POLY;
} else if (lat == pLat && lon == pLon) {
/* drop small distance intermediate nodes */

View File

@ -20,12 +20,16 @@ import org.oscim.tiling.ITileDataSink;
import org.oscim.tiling.ITileDataSource;
import org.oscim.tiling.QueryResult;
import org.oscim.tiling.TileDataSink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
public class MultiMapDatabase implements ITileDataSource {
private static final Logger log = LoggerFactory.getLogger(MultiMapDatabase.class);
private final boolean deduplicate;
private final List<MapDatabase> mapDatabases = new ArrayList<>();
@ -46,28 +50,34 @@ public class MultiMapDatabase implements ITileDataSource {
@Override
public void query(MapTile tile, ITileDataSink sink) {
boolean deduplicate = this.deduplicate;
if (deduplicate) {
int n = 0;
for (MapDatabase mapDatabase : mapDatabases) {
if (mapDatabase.supportsTile(tile)) {
if (++n > 1) {
break;
try {
boolean deduplicate = this.deduplicate;
if (deduplicate) {
int n = 0;
for (MapDatabase mapDatabase : mapDatabases) {
if (mapDatabase.supportsTile(tile)) {
if (++n > 1) {
break;
}
}
}
deduplicate = n > 1;
}
deduplicate = n > 1;
}
TileDataSink dataSink = new TileDataSink(sink);
for (int i = 0, n = mapDatabases.size(); i < n; i++) {
MapDatabase mapDatabase = mapDatabases.get(i);
if (mapDatabase.supportsTile(tile)) {
mapDatabase.setDeduplicate(deduplicate);
dataSink.level = i + 1;
dataSink.levels = n;
mapDatabase.query(tile, dataSink);
TileDataSink dataSink = new TileDataSink(sink);
for (int i = 0, n = mapDatabases.size(); i < n; i++) {
MapDatabase mapDatabase = mapDatabases.get(i);
if (mapDatabase.supportsTile(tile)) {
mapDatabase.setDeduplicate(deduplicate);
dataSink.level = i + 1;
dataSink.levels = n;
mapDatabase.query(tile, dataSink);
}
}
} catch (Throwable t) {
log.error(t.getMessage(), t);
sink.completed(QueryResult.FAILED);
return;
}
sink.completed(QueryResult.SUCCESS);
}