【发布时间】:2015-12-02 18:06:25
【问题描述】:
我不明白OnlineTileSourceBase 类中aBaseUrl 参数的用途。我询问的原因是我试图让离线磁贴显示,但到目前为止还不能让它工作。我看到了我创建的叠加层,但没有地图数据(只有那个灰色网格),我想知道是否需要将 aBaseUrl 设置为适当的值。
设备上的数据在 sdcard/osmdroid/tiles/Mapnik/ 中。 Mapnik 包含文件夹 0, 1, ... 14,这些文件夹本身包含包含 .jpg 文件的文件夹。
在线,此代码有效(删除调用 setUseDataConnection(false) 并将平铺源设置为 MAPNIK)。基于@nightfixed here 的代码。
public class MapActivity extends AppCompatActivity {
final private int MIN_ZOOM_LEVEL = 0;
final private int MAX_ZOOM_LEVEL = 14;
final private int TILE_SIZE = 256;
final private String IMAGE_EXTENSION = ".jpg";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
CustomTileSource tileSource = new CustomTileSource ("Default",
MIN_ZOOM_LEVEL,
MAX_ZOOM_LEVEL,
TILE_SIZE,
IMAGE_EXTENSION,
CustomTileSource.TILE_URL);
final MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(tileSource);
// mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setUseDataConnection(false); // keeps the mapView from loading online tiles using network connection.
}
}
public class CustomTileSource extends OnlineTileSourceBase {
public static String[] TILE_URL = {"my_url"};
public CustomTileSource (String aName,
int aZoomMinLevel,
int aZoomMaxLevel,
int aTileSizePixels,
String aImageFilenameEnding,
String[] urlArray) {
super(
aName,
aZoomMinLevel,
aZoomMaxLevel,
aTileSizePixels,
aImageFilenameEnding,
urlArray);
}
// 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();
}
}
【问题讨论】: