Android Osmdroid bonuspack - 在 infoWindow 操作后更改标记标题

Android Osmdroid bonuspack - change marker title after infoWindow action

使用 Android Osmdroid Bonuspack 我创建了一个带有自定义 InfoWindow 的标记。

marker = new MarkerWithLabel( mv, mapDescription6);
marker.setTitle( description); 
marker.setSubDescription( gcId); 
marker.setPosition( gp);
marker.setIcon( bubble); 
marker.setAnchor( 0.5f, 1.0f);
marker.setInfoWindow( new MapGeocacheAction( mv, this, gp, etc.));

在信息​​窗口中我有几个按钮。按下一个按钮时,我想更改原始标记标题(例如,名称后面有一个星号)。

如何在单击按钮(信息窗口消失)后更改标记标题(实时)以使用不同的名称?

De MarkerWithLabel 代码是:

public class MarkerWithLabel extends Marker {
    Paint textPaint; 
    String mLabel; 
    public MarkerWithLabel(MapView mv, String l) {
        super( mv);
        mLabel = l; 
        textPaint = new Paint();
        textPaint.setColor( Color.RED);
        textPaint.setTextSize( dim25sp);
        textPaint.setAntiAlias(true);
        textPaint.setTextAlign(Paint.Align.LEFT);
    }
    public void draw( final Canvas c, final MapView osmv, boolean shadow) {
        draw( c, osmv); 
    }
    public void draw( final Canvas c, final MapView osmv) {
        super.draw( c, osmv, false); 
        Point p = this.mPositionPixels;
        c.drawText( mLabel, p.x, p.y+20, textPaint); 
    }

}

编辑 使用 MKer 的解决方案:

1 - 获取 v5.1 版本的 Osmonuspack。

2 - 在 WindowWindow 添加按钮点击:

mMarkerRef.setTitle( title.substring( 2));

3 - 在 MarkerWithLabel 中:使用标题(不是标签):

c.drawText( getTitle(), p.x, p.y+20, textPaint); 

我假设您的 MapGeocacheAction 继承自 MarkerInfoWindow。

MarkerInfoWindow 使用 mMarkerRef 属性保留打开它的标记的句柄。它受到保护,因此您可以在 MapGeocacheAction 中访问它。

所以在您的按钮点击处理程序中,在关闭 window 之前,您可以设置:

mMarkerRef.setTitle(newTitle);