OSMDroid 切換地圖不更新的問題
阿新 • • 發佈:2018-11-05
用OSMDroid載入Google地圖的時候 需要有按鈕切換不同圖層的地圖,如果發現呼叫了mMapView.setTileSource(ITileSource aTileSource)方法的時候發現地圖View沒有更新的話,可能是因為兩個例項化TileSource物件其子類BitmapTileSourceBase這個類的aName成員變數值一樣導致的地圖在setTileSource出現不更新問題,只要在new XYTileSource的時候構造器的aName在不同的例項化物件中設定為不同的name就好了,望大家注意這點。
package org.osmdroid.tileprovider.tilesource; import org.osmdroid.util.MapTileIndex; public class XYTileSource extends OnlineTileSourceBase { public XYTileSource(String aName, int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels, String aImageFilenameEnding, String[] aBaseUrl) { this(aName, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels, aImageFilenameEnding, aBaseUrl, (String)null); } public XYTileSource(String aName, int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels, String aImageFilenameEnding, String[] aBaseUrl, String copyright) { super(aName, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels, aImageFilenameEnding, aBaseUrl, copyright); } public String toString() { return this.name(); } public String getTileURLString(long pMapTileIndex) { return this.getBaseUrl() + MapTileIndex.getZoom(pMapTileIndex) + "/" + MapTileIndex.getX(pMapTileIndex) + "/" + MapTileIndex.getY(pMapTileIndex) + this.mImageFilenameEnding; } }