开发者

How can I change an overlay's icon from Android's MapView class?

I'm working on a map in Android, with several overlay icons covering it. My problem is that each overlay's icon is static and does not resize with the rest of the map when zooming in and out. This can become awkward if the user zooms too far in or out and the icons appear too big or too small.

My solution is to create multiple image files with different sizes of each icon. However, I'm not sure how to reference these icons from my (extended) MapView class after I've already created them from my :

public class Map extends MapActivity {
    ...
    public onCreate() {
        ...
        //Very simplified copy of my working code:

        Drawable defaultDrawable = this.getResources().getDrawable(R.drawable.myicon);
        List<Overlay> mapOverlays = mapView.getOverlays();
        ItemizedOverlay overlayManager = new OverlayManager(defaultDrawable, this);
        OverlayItem myOverlay =  new OverlayItem(...);
        overlayManager.addOverlay(myOverlay);
    }
}

I extended the MapView class so that I could trigger zoom events. The dispatchDraw() method is where I plan to place my icon-replacement code, but I'm not sure how I can access the map's existing overlays and their icons from here (and change just their icons):

public class ZoomSensitiveMapView extends MapView {

    private int oldZoomLevel;

    ...

    public void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        if (getZoomLevel() != oldZoomLevel) {

            if (getZoomLevel() > 15) {
                //Zoomed in closer
                //Replace icons with bigger copies
            }
            else {
                //Zoomed out further
                //Replace icons with smaller copies
            }
            oldZoomLevel = getZoomLevel();
        }
    }
}

I was thinking getOverlays(开发者_开发技巧) might work here, but that seems to only return the overlays themselves, not their icons.

Am I on the right track? How can I replace the icons without adjusting their overlay coordinates, etc.? Any help or recommendations would be greatly appreciated here! (Hopefully my explanation is clear enough; if anything is not, please ask me to clarify!) Thanks in advance for your help!


here you can change with line ::

Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);

just put your own icon in drawable folder and update with

Drawable drawable = this.getResources().getDrawable(R.drawable.yourIcon);

For more information :: get from here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜