2013-11-04 19 views
1

我想添加一個路徑覆蓋到OSMDroid地圖,它不出現。我錯過了什麼?OSMDroid PathOverlay沒有出現

更新:

我想通了,它是與瓷磚的大小。即使拼貼是256,我也將尺寸設置爲512,否則地圖太小而無法在高像素密度屏幕上讀取。如果我將大小更改爲256,則顯示路徑。如果我將其更改回512,則不會顯示。

public class MainActivity extends Activity { 

    // set this to 256 for actual tile size, 512 to show larger and cause PathOverlay to not be displayed 
    int tileSize = 512; 

    private MapView mapView; 

    // area of offline tiles 
    double north = 40.739063; 
    double south = 40.708361; 
    double west = -73.967171; 
    double east = -73.936272; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 

     // center of offline tiles 
     double centerlat = (double) ((north+south)/2); 
     double centerlon = (double) ((west+east)/2); 

     // copy tiles to sd location for offline map 
     putMapOnSD(); 

     // create mapView and show layout 
     mapView = new MapView(this,tileSize); 
     final LinearLayout layout = new LinearLayout(this); 
     final LinearLayout.LayoutParams mapViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); 
     layout.addView(mapView, mapViewLayoutParams); 
     setContentView(layout); 

     // set map to use offline tiles and display 
     mapView.setTileSource (new XYTileSource ("tiles", ResourceProxy.string.offline_mode, 13, 17, tileSize, ".png", "http://127.0.0.1")); 
     mapView.setUseDataConnection(false); 
     mapView.setClickable(false); 
     mapView.setMultiTouchControls(true); 
     mapView.setBuiltInZoomControls(false); 
     mapView.getController().setZoom(15); 
     mapView.getController().setCenter(new GeoPoint(centerlat,centerlon)); 

     // show pathOverlay 
     PathOverlay pathOverlay = new PathOverlay(Color.RED, this); 
     pathOverlay.addPoint(new GeoPoint(centerlat,centerlon)); 
     centerlat += 0.005; 
     pathOverlay.addPoint(new GeoPoint(centerlat,centerlon)); 
     centerlon += 0.005; 
     pathOverlay.addPoint(new GeoPoint(centerlat,centerlon)); 
     pathOverlay.getPaint().setStrokeWidth(10.0f); 
     mapView.getOverlays().add(pathOverlay); 

     // refresh map, is this needed? 
     mapView.invalidate(); 
    } 


    // this copies the offline tiles to the proper location for OSMDroid to use them offline 
    private void putMapOnSD() { 
     // see GitHub for this 
    } 
} 

在GitHub上獲取完整的項目。 https://github.com/tomkincaid/PathExample

我使用Cloudmade的@ 2x圖塊解決了這個問題,所以我不必爲高密度屏幕使用512像素大小。儘管有人想調查,但基本問題仍然存在。

+0

如果較大的瓷磚尺寸couse路徑覆蓋不令人滿意,您可能必須發揮您的地理座標增加其他任何差異或大小:)一旦這對我工作:) – ismail

回答

4

嘗試將中風的Paint添加到PathOverlay

Paint paint = new Paint(); 
paint.setAlpha(155); 
paint.setColor(Color.argb(205, 178, 255, 255)); 
paint.setStyle(Style.STROKE); 
paint.setStrokeWidth(10); 
pathOverlay.setPaint(paint); 

更新: 我想,爲什麼你的路徑沒有出現,直接關係到Tile Size參數的主要原因。因爲在繪製pathOVerlay時,所有投影和線條計算都基於此參數。因此,如果將其設置爲不是實際大小的圖塊,則計算將失敗並且不顯示覆蓋路徑。

+0

仍然不顯示。 –

+0

由於之前我使用了帶路徑覆蓋的OSMDroid地圖,因此我會要求您發佈地圖活動的整個代碼,以便我可以提供幫助。 –

+0

謝謝蒂姆。代碼中有很多額外的東西。我將不得不清理它以清楚地說明例子。我發現Cloudmade以2x提供了瓷磚,因此它實際上解決了這個問題。我可以使用他們的瓷磚在256. –