2014-04-03 34 views
1

我有離線osmdroid地圖工作使用版本4.0。升級到4.1,他們不再工作。我將問題縮小到了XYTileSource,其中aBaseUrl從4.0中的字符串變爲4.1中的數組,並且變爲4.1中的數組。如何讓離線切片在4.1中工作?如何在版本4.1中爲離線切片創建osmdroid XYTileSource?

工作的舊4.0代碼。瓷磚在/sdcard/osmdroid/tiles.zip

XYTileSource ts = new XYTileSource ("tiles", 
             ResourceProxy.string.offline_mode, 
             13, 
             17, 
             256, 
             ".png", 
             "http://127.0.0.1"); 

mapView = (MapView) findViewById(R.id.mapview); 
mapView.setTileSource(ts); 
mapView.setMultiTouchControls(true); 
mapView.setBuiltInZoomControls(false); 
mapView.setUseDataConnection(false); 
mapView.getController().setZoom(15); 
GeoPoint point = new GeoPoint(40.715,-73.945); 
mapView.getController().setCenter(point); 

我試着改變它到這,但它不起作用。

String[] urls = {"http://127.0.0.1"}; 
XYTileSource ts = new XYTileSource ("tiles", 
             ResourceProxy.string.offline_mode, 
             13, 
             17, 
             256, 
             ".png", 
             urls); 
+0

我認爲aBaseUrl更改不相關,特別是因爲您沒有使用在線服務器。你應該嘗試通過瓷磚供應商,看看他們是否返回瓷磚。 – kurtzmarc

+0

在線提供商工作。這只是我用於離線切片的相同代碼,因此我不再使用4.1。 –

+0

我想我放棄了osmdroid,並把單張放在webview中。它的性能要好得多,而且它可以只使用文件系統中的離線磁貼,而不是使用zip。 osmdroid在大型zip文件中遇到了內存問題。 –

回答

2

我試圖提供一個完整的答案在這裏: Download maps for osmdroid

如果你有一個 「老」 tiles.zip,打開它,並檢查:

  • 根目錄名稱= >把它作爲XYTileSource構造函數的「aName」(它真的是「瓷磚」?)
  • 瓷磚圖像擴展=>把它作爲aImageFileNameEnding(它真的是「.png」?)

aResourceId和aBaseUrl參數不用於zip文件。

+0

是的,它被稱爲tiles.zip,在zip中有一個名爲tiles的路徑,如/tiles/1/2/3.png。我嘗試使用和不使用路徑中的tiles目錄。 –

2

我看到您使用的是XYTileSource,默認情況下它延伸到OnlineTileSourceBase

我找到了Url問題的解決辦法,通過創建一個CustomTileSource類。類似下面:

public class CustomTileSource extends OnlineTileSourceBase { 

public static String[] TILE_URL = {"my_url"}; 

//constructor is default - I changed nothing here 
    public CustomTileSource (String aName, string aResourceId, int aZoomMinLevel, int aZoomMaxLevel, 
      int aTileSizePixels, String aImageFilenameEnding, String[] url) { 
     super(
       aName, 
       aResourceId, 
       aZoomMinLevel, 
       aZoomMaxLevel, 
       aTileSizePixels, 
       aImageFilenameEnding, 
       url); 
     // TODO Auto-generated constructor stub 
    } 

    /** 
    * 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(); 
    } 
} 

在我的代碼,在那裏我需要實例化tilesource,我使用:

CustomTileSource tileSource = new CustomTileSource ("Default", ResourceProxy.string.offline_mode, MIN_ZOOM_LVL, MAX_ZOOM_LVL, DEFAULT_TILE_SIZE, TILE_FORMAT, CustomTileSource.TILE_URL); 
//MIN_ZOOM_LVL, MAX_ZOOM_LVL, DEFAULT_TILE_SIZE, TILE_FORMAT are constants that I defined elsewhere 

希望它能幫助。

+0

請注意,在較新版本的OSMDroid中,'OnlineTileSourceBase'在其構造函數中沒有'aResourceId'。 –

+0

** my_url **有意義嗎?如果是這樣,當平板在設備上時,例如* Tablet \ osmdroid \ tiles \ Mapnik *應該是什麼? –