org.osmdroid.mapsforge.MapsForgeTileProvider

Here are the examples of the java api class org.osmdroid.mapsforge.MapsForgeTileProvider taken from open source projects.

1. MapActivity#setMapsForgeTileProvider()

Project: osmbonuspack
File: MapActivity.java
boolean setMapsForgeTileProvider() {
    String path = Environment.getExternalStorageDirectory().getPath() + "/mapsforge/";
    File folder = new File(path);
    File[] listOfFiles = folder.listFiles();
    if (listOfFiles == null)
        return false;
    /*
		File mapFile = null;
		for (File file:listOfFiles){
			if (file.isFile() && file.getName().endsWith(".map")){
				mapFile = file;
			}
		}
		if (mapFile == null)
			return false;
		//TODO: build a list with only .map files; get rendering config file if any.
		*/
    if (AndroidGraphicFactory.INSTANCE == null)
        AndroidGraphicFactory.createInstance(this.getApplication());
    MapsForgeTileProvider mfProvider = new MapsForgeTileProvider(new SimpleRegisterReceiver(this), MapsForgeTileSource.createFromFiles(listOfFiles));
    map.setTileProvider(mfProvider);
    return true;
}

2. MainActivity#onCreate()

Project: osmdroid
File: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /**
         * super important to configure some of the mapsforge settings first
         */
    AndroidGraphicFactory.createInstance(this.getApplication());
    // Request permissions to support Android Marshmallow and above devices
    if (Build.VERSION.SDK_INT >= 23) {
        checkPermissions();
    }
    setContentView(R.layout.activity_main);
    mMap = (MapView) findViewById(R.id.mapview);
    currentCenter = (TextView) findViewById(R.id.currentCenter);
    //first let's up our map source, mapsforge needs you to explicitly specify which map files to load
    //this bit does some basic file system scanning
    Set<File> mapfiles = findMapFiles();
    //do a simple scan of local storage for .map files.
    File[] maps = new File[mapfiles.size()];
    maps = mapfiles.toArray(maps);
    if (maps.length == 0) {
        //show a warning that no map files were found
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        // set title
        alertDialogBuilder.setTitle("No Mapsforge files found");
        // set dialog message
        alertDialogBuilder.setMessage("In order to render map tiles, you'll need to either create or obtain mapsforge .map files. See https://github.com/mapsforge/mapsforge for more info.").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
            }
        });
        // create alert dialog
        AlertDialog alertDialog = alertDialogBuilder.create();
        // show it
        alertDialog.show();
    } else
        Toast.makeText(this, "Loaded " + maps.length + " map files", Toast.LENGTH_LONG).show();
    //this creates the forge provider and tile sources
    //that's it!
    //note this example does not using caching yet, so each tile is rendered on the fly, every time
    //the user browses to an area. This needs to be updated to support sqlite raster image caches
    //protip: when changing themes, you should also change the tile source name to prevent cached tiles
    //null is ok here, uses the default rendering theme if it's not set
    XmlRenderTheme theme = null;
    try {
        theme = new AssetsRenderTheme(getApplicationContext(), "renderthemes/", "rendertheme-v4.xml");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    MapsForgeTileProvider forge = new MapsForgeTileProvider(new SimpleRegisterReceiver(this), MapsForgeTileSource.createFromFiles(maps, theme, "rendertheme-v4"));
    mMap.setTileProvider(forge);
    mMap.setUseDataConnection(false);
    mMap.setMultiTouchControls(true);
    mMap.setBuiltInZoomControls(true);
}