use TileClipper for mapsforge tiles

This commit is contained in:
Hannes Janetzek 2013-10-06 21:19:11 +02:00
parent d44489819a
commit eb8fd81aef

View File

@ -29,6 +29,7 @@ import org.oscim.tiling.MapTile;
import org.oscim.tiling.source.ITileDataSink; import org.oscim.tiling.source.ITileDataSink;
import org.oscim.tiling.source.ITileDataSource; import org.oscim.tiling.source.ITileDataSource;
import org.oscim.tiling.source.mapfile.header.SubFileParameter; import org.oscim.tiling.source.mapfile.header.SubFileParameter;
import org.oscim.utils.TileClipper;
/** /**
* A class for reading binary map files. * A class for reading binary map files.
@ -253,8 +254,8 @@ public class MapDatabase implements ITileDataSource {
* the callback which handles the extracted map elements. * the callback which handles the extracted map elements.
*/ */
private void processBlock(QueryParameters queryParameters, private void processBlock(QueryParameters queryParameters,
SubFileParameter subFileParameter, SubFileParameter subFileParameter, ITileDataSink mapDataSink) {
ITileDataSink mapDataSink) {
if (!processBlockSignature()) { if (!processBlockSignature()) {
return; return;
} }
@ -302,12 +303,16 @@ public class MapDatabase implements ITileDataSource {
// move the pointer to the first way // move the pointer to the first way
mReadBuffer.setBufferPosition(firstWayOffset); mReadBuffer.setBufferPosition(firstWayOffset);
if (!processWays(queryParameters, mapDataSink, waysOnQueryZoomLevel)) { if (!processWays(queryParameters, mapDataSink, waysOnQueryZoomLevel)) {
return; return;
} }
} }
private long mCurrentRow;
private long mCurrentCol;
private void processBlocks(ITileDataSink mapDataSink, private void processBlocks(ITileDataSink mapDataSink,
QueryParameters queryParameters, QueryParameters queryParameters,
SubFileParameter subFileParameter) throws IOException { SubFileParameter subFileParameter) throws IOException {
@ -315,8 +320,10 @@ public class MapDatabase implements ITileDataSource {
// boolean queryReadWaterInfo = false; // boolean queryReadWaterInfo = false;
// read and process all blocks from top to bottom and from left to right // read and process all blocks from top to bottom and from left to right
for (long row = queryParameters.fromBlockY; row <= queryParameters.toBlockY; ++row) { for (long row = queryParameters.fromBlockY; row <= queryParameters.toBlockY; row++) {
for (long column = queryParameters.fromBlockX; column <= queryParameters.toBlockX; ++column) { for (long column = queryParameters.fromBlockX; column <= queryParameters.toBlockX; column++) {
mCurrentCol = column - queryParameters.fromBlockX;
mCurrentRow = row - queryParameters.fromBlockY;
// calculate the actual block number of the needed block in the // calculate the actual block number of the needed block in the
// file // file
@ -701,8 +708,7 @@ public class MapDatabase implements ITileDataSource {
* otherwise. * otherwise.
*/ */
private boolean processWays(QueryParameters queryParameters, private boolean processWays(QueryParameters queryParameters,
ITileDataSink mapDataSink, ITileDataSink mapDataSink, int numberOfWays) {
int numberOfWays) {
Tag[] wayTags = mTileSource.fileInfo.wayTags; Tag[] wayTags = mTileSource.fileInfo.wayTags;
int numTags = 0; int numTags = 0;
@ -719,6 +725,36 @@ public class MapDatabase implements ITileDataSource {
mReadBuffer.skipBytes(stringsSize); mReadBuffer.skipBytes(stringsSize);
} }
long numRows = queryParameters.toBlockY - queryParameters.fromBlockY;
long numCols = queryParameters.toBlockX - queryParameters.fromBlockX;
//Log.d(TAG, numCols + "/" + numRows + " " + mCurrentCol + " " + mCurrentRow);
if (numRows > 0) {
int minX = -2;
int minY = -2;
int maxX = Tile.SIZE + 2;
int maxY = Tile.SIZE + 2;
int w = (int) (Tile.SIZE / (numCols + 1));
int h = (int) (Tile.SIZE / (numRows + 1));
if (mCurrentCol > 0)
minX = (int) (mCurrentCol * w);
if (mCurrentCol < numCols)
maxX = (int) (mCurrentCol * w + w);
if (mCurrentRow > 0)
minY = (int) (mCurrentRow * h);
if (mCurrentRow < numRows)
maxY = (int) (mCurrentRow * h + h);
//Log.d(TAG, minX + " " + minY + " " + maxX + " " + maxY);
mTileClipper.setRect(minX, minY, maxX, maxY);
} else {
mTileClipper.setRect(-2, -2, Tile.SIZE + 2, Tile.SIZE + 2);
}
for (int elementCounter = numberOfWays; elementCounter != 0; --elementCounter) { for (int elementCounter = numberOfWays; elementCounter != 0; --elementCounter) {
if (mDebugFile) { if (mDebugFile) {
// get and check the way signature // get and check the way signature
@ -856,6 +892,12 @@ public class MapDatabase implements ITileDataSource {
projectToTile(mElem); projectToTile(mElem);
if (mElem.isPoly()) {
if (!mTileClipper.clip(mElem)) {
continue;
}
}
mElem.setLayer(layer); mElem.setLayer(layer);
mapDataSink.process(mElem); mapDataSink.process(mElem);
} }
@ -864,6 +906,8 @@ public class MapDatabase implements ITileDataSource {
return true; return true;
} }
private final TileClipper mTileClipper = new TileClipper(-2, -2, Tile.SIZE + 2, Tile.SIZE + 2);
private float[] readOptionalLabelPosition() { private float[] readOptionalLabelPosition() {
float[] labelPosition = new float[2]; float[] labelPosition = new float[2];
@ -883,7 +927,7 @@ public class MapDatabase implements ITileDataSource {
int cumulatedNumberOfPois = 0; int cumulatedNumberOfPois = 0;
int cumulatedNumberOfWays = 0; int cumulatedNumberOfWays = 0;
for (int row = 0; row < rows; ++row) { for (int row = 0; row < rows; row++) {
cumulatedNumberOfPois += mReadBuffer.readUnsignedInt(); cumulatedNumberOfPois += mReadBuffer.readUnsignedInt();
cumulatedNumberOfWays += mReadBuffer.readUnsignedInt(); cumulatedNumberOfWays += mReadBuffer.readUnsignedInt();