开发者

Can panning/zooming be disabled in an android MapView while allowing users to click on an ItemizedOverlay?

开发者 https://www.devze.com 2023-03-14 11:55 出处:网络
Is there a way of disabling panning/zooming and keeping map overlays clickable? I am specifically thinking about an ItemizedOverlay that I want to be tappable while denying users from moving around t

Is there a way of disabling panning/zooming and keeping map overlays clickable?

I am specifically thinking about an ItemizedOverlay that I want to be tappable while denying users from moving around the map's viewport (It's for a game).

I've seen the same 开发者_高级运维question answered but the answer sadly doesn't allow for overlay items to be clicked.

Thanks alot, best regards, Alex


I know this question is a little old but I had the same problem and found a workaround, it's not a graceful solution but appears to work.

First you have to create your own map subclass overriding the onTouchEvent handler

public class NonPannableMapView extends MapView {

    public NonPannableMapView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);    
    }

    public NonPannableMapView(Context context, AttributeSet attrs){
        super(context, attrs);
    }

    public NonPannableMapView(Context context, String apiKey) {
         super(context, apiKey);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
          //Handle a move so there is no panning or zoom
          if(ev.getAction() == MotionEvent.ACTION_MOVE)
              return true;
      return super.onTouchEvent(ev);
    }
}

Then it's just a case of changing the MapView reference in your layout to NonPannableMapView.


Try this:

mapView.setBuiltInZoomControls(false);

Hope that works! Have fun!

0

精彩评论

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