Skip to content

Instantly share code, notes, and snippets.

@virtualvoid
Last active November 16, 2015 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virtualvoid/9eac3974934e2bd55bb1 to your computer and use it in GitHub Desktop.
Save virtualvoid/9eac3974934e2bd55bb1 to your computer and use it in GitHub Desktop.
osmdroid density based TileSource
package sk.virtualvoid.osmdroid;
import android.content.Context;
import org.osmdroid.tileprovider.tilesource.XYTileSource;
/**
* Created by suchan_j on 16.11.2015.
*/
public class DensityBasedTileSource {
private static final String key = "OSM";
private static final String imageFormat = ".png";
private static final Integer minZoomLevel = 1;
private static final Integer maxZoomLevel = 18;
public static XYTileSource getTileSource(Context context) {
final float scale = context.getResources().getDisplayMetrics().density;
final int newScale = (int) (256 * scale);
String[] osmSources = new String[] {
"http://a.tile.openstreetmap.org/",
"http://b.tile.openstreetmap.org/",
"http://c.tile.openstreetmap.org/"
};
XYTileSource tileSource = new XYTileSource(key, null, minZoomLevel, maxZoomLevel, newScale, imageFormat, osmSources);
return tileSource;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment