2012-08-22 74 views
0

我想繪製可見的OverlayItems,這就是爲什麼我確定地圖可見矩形,但我無法確定畫布將繪製OverlayItem的Rect。從畫布確定繪製矩形(確定OverlayItem的位置)

那是我做了什麼至今(以逐項疊加法)..但getClipBounds()不返回正確的矩形

@Override 
    public void draw(Canvas canvas, MapView map, boolean shadow) { 
     if (getMapBounds().intersect(canvas.getClipBounds())) { 
      super.draw(canvas, map, false); 
     } 
    } 

我不想畫等OverlayItems,我想知道我的畫布因爲如果不是我不畫這個帆布 這樣做是爲了加快有近2000項疊加

+1

問題不理解.Didü詳細解釋? – saravanan

回答

0

我現在這樣做是通過循環項目,並檢查它們是否是在地圖上還是不就像這樣:

@Override 
    public void draw(Canvas canvas, MapView map, boolean shadow) { 
     for (int i = 0; i < mOverlays.size(); i++) { 
      if (isLocationVisible(mOverlays.get(i).getPoint())) { 
       super.draw(canvas, map, false); 
      } 
     }  
    } 
0

如果您正在尋找繪製的MapView地圖視圖 可見rects內畫點什麼覆蓋像這些:

所以基本上你要做的是在畫布的幫助下將customImage強加在背景框上。使用此實現,您可以從畫布中有效地創建一個BitmapDrawable,然後您可以將其指定爲「ItemizedOverlay」的標記。如果這是您正在尋找的逐項疊加的類型,那麼就不需要重寫逐項疊加類的繪製函數。所有你需要做的就是使用下面的代碼來創建一個BitmapDrawable,你可以在它的構造函數中分配給你的ItemizedOverlay。下面是做到這一點的功能:

public BitmapDrawable imageOnDrawable(int drawableBackground, Bitmap customImage) 
{ 
//The following line is optional but I'd advise you to minimize the size of 
//the size of the bitmap (using a thumbnail) in order to improve draw 
//performance of the overlays (especially if you are creating a lot of overlays). 

Bitmap customImageThumbnail = ThumbnailUtils.extractThumbnail(
               customImage, 100, 100); 

Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId); 
bm = Bitmap.createScaledBitmap(bm, 112, 120, false); 

Canvas canvas = new Canvas(bm); 
canvas.drawBitmap(bm, 0, 0, null); 
// The 6,6 in the below line refer to the offset of the customImage/Thumbnail 
// from the top-left corner of the background box (or whatever you want to use 
// as your background) 
canvas.drawBitmap(customImageThumbnail, 6, 6, null); 

return new BitmapDrawable(bm); 

} 
+0

我有OverlayItems我正在繪製我不知道的是,如果此畫布在地圖視圖的可見矩形內繪製疊加項或不......因爲如果不是,我不會繪製疊加圖以提高地圖的速度查看 – lukaswelte

+0

這似乎很難確定,只是基於畫布,因爲畫布沒有它自己的地理方位,而包含在項目化疊加層中的疊加層有他們自己的GeoPoints。所以我想知道是否使用Itemized Overlay作爲多個疊加層的容器,或者是否爲每個疊加層使用不同的分項疊加層對象? –

+0

一個分項疊加包含多個OverlayItems,但是有多個分項疊加...因此,在OverlayItem的Draw中這樣做更好/更容易嗎?如果是的話,我怎麼能得到那裏繪製的矩形? – lukaswelte