这里 Android SDK OffscreenRenderer MapOverlay 未显示
Here Android SDK OffscreenRenderer MapOverlay not shown
我使用Android Here SDK 和OffscreenRenderer 渲染地图实例。
我想用 MapOverlay 绘制自定义气泡视图。对于正常呈现的地图(在 Activity 内有 mapFragment),我可以按照手册中的描述添加 MapOverlay 对象:
Button button = new Button(this);
button.setText("TEST");
myMap.addMapOverlay(new MapOverlay(button, destination));
对于 mapFragment 这很好用,但是对于 OffscreenRenderer 我在地图上看不到按钮。我在上面尝试了不同的视图、膨胀的布局和简单的按钮代码——所有这些似乎都适用于常规地图,但不适用于 OffscreenRenderer。 SDK 是否提供此功能?我怎样才能让它出现?
更新: addMapOverlay returns 正确。
更新 2:
Post 建议解决方案的工作代码示例。我们需要从视图 (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;
}
MapOverlays 使用 Android 视图,因此它们不能通过屏幕外渲染器工作。
在这种情况下,请回退到常规地图标记。您可以将 Android 视图膨胀并渲染到位图中,并将其用作标记的纹理。
我使用Android Here SDK 和OffscreenRenderer 渲染地图实例。
我想用 MapOverlay 绘制自定义气泡视图。对于正常呈现的地图(在 Activity 内有 mapFragment),我可以按照手册中的描述添加 MapOverlay 对象:
Button button = new Button(this);
button.setText("TEST");
myMap.addMapOverlay(new MapOverlay(button, destination));
对于 mapFragment 这很好用,但是对于 OffscreenRenderer 我在地图上看不到按钮。我在上面尝试了不同的视图、膨胀的布局和简单的按钮代码——所有这些似乎都适用于常规地图,但不适用于 OffscreenRenderer。 SDK 是否提供此功能?我怎样才能让它出现?
更新: addMapOverlay returns 正确。 更新 2:
Post 建议解决方案的工作代码示例。我们需要从视图 (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;
}
MapOverlays 使用 Android 视图,因此它们不能通过屏幕外渲染器工作。
在这种情况下,请回退到常规地图标记。您可以将 Android 视图膨胀并渲染到位图中,并将其用作标记的纹理。