1

Sorry for my bad English, i have a question. I'm new in android and don't know how to do this.

How can i modify OSMdroid 4.2 jar file codes in my project?

I added these jar files as library to my project. My app in 3 languages. I have tile source for every language. When I select language, program selects a tile source with the same language. But when i zoom map, automatically language changes in map. I don't know why it do this. I think it depends on tiles cach in storage.
Is there any way to change tile cache in storage for every language individually?
Thanks! :)

Ichigo Kurosaki
  • 3,765
  • 8
  • 41
  • 56
Behruz Qazizade
  • 55
  • 1
  • 10

2 Answers2

3

See: https://github.com/osmdroid/osmdroid/issues/78 This is the same issue (OSMDROID_PATH and TILE_PATH_BASE hardcoded and final).

Using this patch (potentially old version below), you could change the tile cache path as needed.

package org.osmdroid.tileprovider.constants;

import java.io.File;
import android.os.Environment;

/**
 * This class contains key settings related to the osmdroid cache, and methods to change default values. 
 */
public class TilesCacheSettings {

    /** Base path for osmdroid files. Zip files are in this folder. */
    public static File OSMDROID_PATH = new File(Environment.getExternalStorageDirectory(),
            "osmdroid");

    /** Base path for tiles. */
    public static File TILE_PATH_BASE = new File(OSMDROID_PATH, "tiles");

    /** 600 Mb */
    public static long TILE_MAX_CACHE_SIZE_BYTES = 600L * 1024 * 1024;

    /** 500 Mb */
    public static long TILE_TRIM_CACHE_SIZE_BYTES = 500L * 1024 * 1024;

    /** Change the root path of the osmdroid cache. 
     * By default, it is defined in SD card, osmdroid directory. 
     * @param newFullPath
     */
    public static void setCachePath(String newFullPath){
        OSMDROID_PATH = new File(newFullPath);
        TILE_PATH_BASE = new File(OSMDROID_PATH, "tiles");
    }

    /** Change the osmdroid tiles cache sizes
     * @param maxCacheSize in Mb. Default is 600 Mb. 
     * @param trimCacheSize When the cache size exceeds maxCacheSize, tiles will be automatically removed to reach this target. In Mb. Default is 500 Mb. 
     */
    public static void setCacheSizes(long maxCacheSize, long trimCacheSize){
        TILE_MAX_CACHE_SIZE_BYTES = maxCacheSize * 1024 * 1024;
        TILE_TRIM_CACHE_SIZE_BYTES = trimCacheSize * 1024 * 1024;
    }

}
Sam Whited
  • 6,880
  • 2
  • 31
  • 37
MKer
  • 3,430
  • 1
  • 13
  • 18
0

Only add the following code in your

OpenStreetMapTileProviderConstants.setCachePath(this.getFilesDir().getAbsolutePath());

or

OpenStreetMapTileProviderConstants.setCachePath("other path");
Cookie Ninja
  • 1,156
  • 15
  • 29