Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

android - Custom information bubble on tap for overlay items using osmdroid

I'm using osmdroid on my new Android project (since I want to be able to use offline maps) but I encounter many difficulties to customize the look 'n feel of the information bubble assigned to an overlay item.

Right now, I'm using an ItemizedOverlayWithFocus overlay to display my items; looking at its code, I noticed the whole thing was drawn in the onDrawFinished method so I tried to create my own custom overlay to override this method but this is pretty difficult to get a result. What I would love to get is something just like this :

The result

How did you guys managed to get a custom information bubble on your projects?

I found a few classes to implement such a thing for Google's MapView (like Jeff Gilfelt's MapView Balloons) but nothing for osmdroid.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

EDIT:

  • This answer was best for older google map apis. In google Map V2 this thing is already given.

You can get the code from https://github.com/galex/android-mapviewballoons

you can get selected balloon from the method of "BalloonItemizedOverlay.java" as follow

private void hideOtherBalloons(List<Overlay> overlays) {
        for(int i=0; i<overlays.size();i++ ){
            if (overlays.get(i) instanceof BalloonItemizedOverlay<?> && overlays.get(i) != this) {
                ((BalloonItemizedOverlay<?>) overlays.get(i)).hideBalloon();
            }else{
                BalloonOverlayView.SELECTED_BALLOON = i;
                Log.i(i+" : Baloon Open", BalloonOverlayView.SELECTED_BALLOON+"");
            }
        }
}

To set the data you can use setBalloonData method of BalloonOverlayView.java file as follow:

protected void setBalloonData(Item item, ViewGroup parent) {
        if (item.getTitle() != null) {
            title.setVisibility(VISIBLE);
            title.setText(item.getTitle());
        } else {
            title.setText("");
            title.setVisibility(GONE);
        }
        if (item.getSnippet() != null) {
            snippet.setVisibility(VISIBLE);
            snippet.setText(item.getSnippet());
        } else {
            snippet.setText("");
            snippet.setVisibility(GONE);
        }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...