Android

I need to add a custom base layer to my map view. My understanding is that map tiles are exactly the same as google tiles. They are static files served in the following format: http: ///tilecache///.png

For example, http: ///tilecache/6/16/26.png is the coast of the bay between Florida Alabama and Mississippi.

How to create a tile overlay?

+5
source share
3 answers

osmdroid (as recommended above) is cool, but pretty big. Some time ago I decided to use http://sourceforge.net/projects/libwlocate/ - it contains functionality for displaying / scrolling / scaling maps, such as osmdroid, but you can use OSM, Google Maps or Google satellite.

An example of how to use it can be found at http://libwlocate.git.sourceforge.net/git/gitweb.cgi?p=libwlocate/libwlocate;a=blob;f=master/android/LocDemo/src/com/ vwp / locdemo / LocDemo.java; h = 5e2134fb7d197258f5f4f6f9021d2fa9ad9f2d9a; hb = HEAD

+2
source

I would recommend using osmdroid . You can extend OnlineTileSourecBase.

public class YourTileSource extends OnlineTileSourceBase implements IStyledTileSource<Integer> {

public YourTileSource (String aName, string aResourceId,
    int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels,
    String aImageFilenameEnding, String aBaseUrl) {
    super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
            aImageFilenameEnding, aBaseUrl);
}

public void setStyle(Integer style) {
    // TODO Auto-generated method stub
}

public void setStyle(String style) {
    // TODO Auto-generated method stub
}

public Integer getStyle() {
    // TODO Auto-generated method stub
    return null;
}

@Override
public String getTileURLString(MapTile aTile) {
    return getBaseUrl() + "/" + aTile.getX() + "/" + aTile.getY() + "/" + aTile.getZoomLevel() + ".png";
}

}

Then add your tile source to your map view:

TileSourceFactory.addTileSource(new YourTileSource ("YourTileSource", null, 1, 20, 256, ".png", "http:///tilecache/"));
mapView.setTileSource(TileSourceFactory.getTileSource("YourTileSource"));

mapView org.osmdroid.views.MapView . OSMdroid google.

osmdroid-android-3.0.8.jar, libs , > a > Java > > , libs. , , osmdroid.

+1

OSMDroid aResourceId , aBaseUrl - String []

public YourTileSource (String aName, 
    int aZoomMinLevel, 
    int aZoomMaxLevel, 
    int aTileSizePixels,
    String aImageFilenameEnding, 
    String[] aBaseUrl) {

    super(aName, 
          aZoomMinLevel, 
          aZoomMaxLevel, 
          aTileSizePixels, 
          aImageFilenameEnding, 
          aBaseUrl);
}
0

All Articles