1

I have offline osmdroid maps working using version 4.0. Upgrading to 4.1, they no longer work. I have narrowed the problem down to the XYTileSource, in which aBaseUrl changed from being a string in 4.0 to and array in 4.1. How do I get offline tiles to work in 4.1?

Old 4.0 code that worked. The tiles are in /sdcard/osmdroid/tiles.zip

XYTileSource ts = new XYTileSource ( "tiles", 
                                      ResourceProxy.string.offline_mode, 
                                      13, 
                                      17, 
                                      256,
                                      ".png",
                                      "http://127.0.0.1");

mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(ts); 
mapView.setMultiTouchControls(true);
mapView.setBuiltInZoomControls(false);
mapView.setUseDataConnection(false); 
mapView.getController().setZoom(15);
GeoPoint point = new GeoPoint(40.715,-73.945);
mapView.getController().setCenter(point);

I tried changing it to this, but it doesn't work.

String[] urls = {"http://127.0.0.1"};
XYTileSource ts = new XYTileSource ( "tiles", 
                                      ResourceProxy.string.offline_mode, 
                                      13, 
                                      17, 
                                      256,
                                      ".png",
                                      urls);
Tom Kincaid
  • 4,887
  • 6
  • 47
  • 72
  • I think the aBaseUrl change is not related, especially since you aren't using an online server. You should try to step through the tile providers to see if they are returning tiles. – kurtzmarc Apr 03 '14 at 22:02
  • The online providers work. It's just my same code for offline tiles that I was using doesn't work anymore with 4.1. – Tom Kincaid Apr 03 '14 at 22:15
  • I think I'm giving up on osmdroid and putting Leaflet in a webview. It's performance is so much better, plus it can use offline tiles just from the filesystem and not in a zip. osmdroid was having memory problems with large zip files. – Tom Kincaid Apr 04 '14 at 17:29

2 Answers2

2

I tried to provide a full answer here: Download maps for osmdroid

If you have an "old" tiles.zip, open it, and check:

  • the root directory name => put it as the "aName" of XYTileSource constructor (is it really "tiles"?)
  • the tiles images extension => put it as the aImageFileNameEnding (is it really ".png"?)

The aResourceId and aBaseUrl params are not used for zip files.

Community
  • 1
  • 1
MKer
  • 3,430
  • 1
  • 13
  • 18
  • Yes it's called tiles.zip and in the zip there is a path called tiles like /tiles/1/2/3.png. I tries it with and without the tiles directory in the path. – Tom Kincaid Apr 04 '14 at 17:28
2

I see that you are using XYTileSource, which by default extends OnlineTileSourceBase.

I have found a workaround for the Url issue, by creating a CustomTileSource class. Something like below:

public class CustomTileSource extends OnlineTileSourceBase {

public static String[] TILE_URL = {"my_url"};

//constructor is default - I changed nothing here
    public CustomTileSource (String aName, string aResourceId, int aZoomMinLevel, int aZoomMaxLevel,
            int aTileSizePixels, String aImageFilenameEnding, String[] url) {
        super(
                aName,
                aResourceId,
                aZoomMinLevel,
                aZoomMaxLevel,
                aTileSizePixels,
                aImageFilenameEnding,
                url);
        // TODO Auto-generated constructor stub
    }

    /**
     * returns the url for each tile, depending on zoom level
     */
    //this is where I changed the return statement to take the first url from the string array of urls
    @Override
    public String getTileURLString(MapTile aTile) {
        return TILE_URL[0] + aTile.getX() + "+" + aTile.getY() + "+" + aTile.getZoomLevel();
    }
}

In my code, where I need to instantiate the tilesource, I use:

 CustomTileSource  tileSource = new CustomTileSource ("Default", ResourceProxy.string.offline_mode, MIN_ZOOM_LVL, MAX_ZOOM_LVL, DEFAULT_TILE_SIZE, TILE_FORMAT, CustomTileSource.TILE_URL);
//MIN_ZOOM_LVL, MAX_ZOOM_LVL, DEFAULT_TILE_SIZE, TILE_FORMAT are constants that I defined elsewhere

Hope it helps.

nightfixed
  • 871
  • 1
  • 12
  • 24
  • Note that in newer versions of OSMDroid, `OnlineTileSourceBase` does not have `aResourceId` in its constructor. – Al Lelopath Dec 01 '15 at 22:39
  • Is **my_url** meaningful? If so what should it be when tiles are on the device at, e.g., *Tablet\osmdroid\tiles\Mapnik*? – Al Lelopath Dec 01 '15 at 22:48