Closed GoogleCodeExporter closed 8 years ago
I updated the draw() method at org.osmdroid.google.overlay.GoogleTilesOverlay
at my local environment to below code. This works for me. I think this fixes
the issue.
==============
@Override
public void draw(final Canvas c, final MapView osmv, final boolean shadow) {
if (DEBUGMODE) {
logger.trace("draw");
}
// Calculate the half-world size
final Projection pj = osmv.getProjection();
final int zoomLevel = osmv.getZoomLevel() - 1;
final int tileSizePx = this.mTileProvider.getTileSource().getTileSizePixels();
// Calculate the tiles needed for each side around the center one.
final int latSpan = osmv.getLatitudeSpan();
final int longSpan = osmv.getLongitudeSpan();
final int topLatitude = osmv.getMapCenter().getLatitudeE6() + latSpan/2;
final int leftLongitude = osmv.getMapCenter().getLongitudeE6() - longSpan/2;
final int bottomLatitude = osmv.getMapCenter().getLatitudeE6() - latSpan/2;
final int rightLongitude = osmv.getMapCenter().getLongitudeE6() + longSpan/2;
final Point leftTopXY = Mercator.projectGeoPoint(topLatitude/1E6, leftLongitude/1E6, zoomLevel, new Point(0,0));
final Point rightBottomXY = Mercator.projectGeoPoint(bottomLatitude/1E6, rightLongitude/1E6, zoomLevel, new Point(0,0));
final int tileNeededAtLeft = leftTopXY.x;
final int tileNeededAtRight = rightBottomXY.x;
final int tileNeededAtTop = leftTopXY.y;
final int tileNeededAtBottom = rightBottomXY.y;
final int mapTileUpperBound = 1 << zoomLevel;
// make sure the cache is big enough for all the tiles
final int numNeeded = (tileNeededAtBottom - tileNeededAtTop + 1)
* (tileNeededAtRight - tileNeededAtLeft + 1);
mTileProvider.ensureCapacity(numNeeded);
/* Draw all the MapTiles (from the upper left to the lower right). */
for (int y = tileNeededAtTop; y <= tileNeededAtBottom; y++) {
for (int x = tileNeededAtLeft; x <= tileNeededAtRight; x++) {
// Construct a MapTile to request from the tile provider.
final int tileY = MyMath.mod(y, mapTileUpperBound);
final int tileX = MyMath.mod(x, mapTileUpperBound);
final MapTile tile = new MapTile(zoomLevel, tileX, tileY);
final Drawable currentMapTile = mTileProvider.getMapTile(tile);
if (currentMapTile != null) {
final GeoPoint gp = new GeoPoint(
(int) (Mercator.tile2lat(y, zoomLevel) * 1E6),
(int) (Mercator.tile2lon(x, zoomLevel) * 1E6));
pj.toPixels(gp, mTilePos);
mTileRect.set(mTilePos.x, mTilePos.y, mTilePos.x + tileSizePx, mTilePos.y + tileSizePx);
currentMapTile.setBounds(mTileRect);
currentMapTile.draw(c);
}
if (DEBUGMODE) {
c.drawText(tile.toString(), mTileRect.left + 1, mTileRect.top + mPaint.getTextSize(), mPaint);
c.drawLine(mTileRect.left, mTileRect.top, mTileRect.right, mTileRect.top, mPaint);
c.drawLine(mTileRect.left, mTileRect.top, mTileRect.left, mTileRect.bottom, mPaint);
}
}
}
// draw a cross at center in debug mode
if (DEBUGMODE) {
final GeoPoint center = osmv.getMapCenter();
final Point centerPoint = pj.toPixels(center, null);
c.drawLine(centerPoint.x, centerPoint.y - 9, centerPoint.x, centerPoint.y + 9, mPaint);
c.drawLine(centerPoint.x - 9, centerPoint.y, centerPoint.x + 9, centerPoint.y, mPaint);
}
}
==============
Original comment by alex.vanderlinden
on 25 Mar 2012 at 6:45
I haven't tested it, but I checked this in in revision 1082. It seems to make
sense ;-)
Original comment by neilboyd
on 26 Mar 2012 at 7:54
Original comment by neilboyd
on 9 Apr 2012 at 2:41
Original issue reported on code.google.com by
alex.vanderlinden
on 25 Mar 2012 at 6:39