开发者

Inflate balloon when item is selected

I have a map activity that has many pins of map, and when I click a pin, a custom balloon opens, showing some information about that pin. Also, I have a search bar, where if you type the name of a knob, the info appears there, but I want it to go to that searched pin. Example: on the map you have different vegetables pins, and when you search ca开发者_开发知识库rrot, the search list will show the element carrot, and when you click on it, the balloon for the carrot pin will inflate. So, my question is : is there some sort of OnTap() void method ? I know, that OnTap(int index) returns a boolean.


create your own itemized overlay, and override the onTap method, and in your main class, make an instance of the itemized overlay, and call overlay.onTap(point)

Sample code:

public class MyItemizedOverlay<Item> extends ItemizedOverlay<OverlayItem> {
    private ArrayList<OverlayItem> m_overlays;
    private MapView mapView;
    final MapController mc;

    public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
        super(boundCenterBottom(defaultMarker), mapView);
        m_overlays = new ArrayList<OverlayItem>();
        mc = mapView.getController();
        populate();
    }

    public void addOverlay(OverlayItem overlay) {
        m_overlays.add(overlay);
        setLastFocusedIndex(-1);
        populate();
    }

    public ArrayList<OverlayItem> getOverlays() {
        return m_overlays;
    }

    public final boolean onTap(int index) {
        GeoPoint point;
        point = createItem(index).getPoint();
        mc.animateTo(point);    
        return true;
    }

    ...
}

In the main class

public class Main extends MapActivity {
    private MapView mapView;
private List<Overlay> mapOverlays;
    private MyItemizedOverlay overlay;
private Drawable pin;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        doAction();
    }

    private void doAction() {
    mapView = (MapView)findViewById(R.id.map_view);
        pin = res.getDrawable(R.drawable.pin);

        overlay = new MyItemizedOverlay(pin, mapView);

        GeoPoint point = new GeoPoint((int)(7*1E6),(int)(42*1E6));
        overlayItem = new OverlayItem(point, "title", "text");

    overlay.addOverlay(overlayItem);

        mapOverlays = mapView.getOverlays();
    mapOverlays.add(overlay);

        //we tap the point here
        overlay.onTap(0);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜