0
我使用Android Here SDK和OffscreenRenderer渲染地圖實例。此處Android SDK OffscreenRenderer MapOverlay未顯示
我想用MapOverlay繪製自定義氣泡視圖。對於地圖,通常呈現(與mapFragment內活動),我可以添加MapOverlay對象如何在手冊中描述:
Button button = new Button(this);
button.setText("TEST");
myMap.addMapOverlay(new MapOverlay(button, destination));
對於mapFragment這個效果很好,但對OffscreenRenderer我沒有在地圖上看到按鈕。我嘗試了以上不同的視圖,誇張的佈局和簡單的按鈕代碼 - 所有這些似乎都適用於常規地圖,但不適用於OffscreenRenderer。此功能是否可在SDK中使用?我怎樣才能讓它出現?
更新: addMapOverlay返回true。 更新2:
推薦解決方案的工作代碼示例。我們需要從視圖(view-shot =)中截屏並從中創建MapMarker。
public MapMarker makeTargetSmallBubbleMarker(Route route, Address address) {
// obtain view
View v = inflater.inflate(R.layout.info_bubble_small, null);
// get the value..
String destination = "";
// inflate value into view sub fields
((TextView) v.findViewById(R.id.destination)).setText(destination);
// if you use 9-patch bubble with donwside arrow for background of your marker
// you need to change anchor point of the marker, so that the arrow will point to location
// instead of bubble appears above the destination
// maybe someone knows a better solution..? Calculate rendered view size
v.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = v.getMeasuredWidth();
int height = v.getMeasuredHeight();
// make view screen-shot
Image bubbleImg = new Image();
bubbleImg.setBitmap(loadBitmapFromView(v, width, height));
MapMarker bubble = new MapMarker(route.getDestination(), bubbleImg);
// here, I want my bubble arrow and whole marker get a 20% offset for down arrow
bubble.setAnchorPoint(new PointF(width/2f, height * 1.2f));
return bubble;
}
private static Bitmap loadBitmapFromView(View v, int width, int height) {
Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
//v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.layout(0, 0, width, height);
v.draw(c);
return b;
}
是的,多數民衆贊成在工作。我用代碼示例更新了我的問題,現在按您的建議工作。 –
謝謝你的樣品! –