我有mapView,我以编程方式处理触摸事件。
问题是:如果mapview的ZoomOut达到最大值,则平移非常小且速度慢,并且使mapView符合ZoomIn,平移越来越大。换句话说:zoomIN越大,平移动作越大。
如何进行平移移动而不是缩放,因此每次移动地图时,无论缩放级别如何,都会移动相同的距离?
这是我的Android客户端
private double savedTouchedX = -1;
private double savedTouchedY = -1;
....
mapView.setOnTouchListener(new MapView.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
int action = event.getAction();
switch(action)
{
case MotionEvent.ACTION_DOWN:
savedTouchedX = event.getX();
savedTouchedY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
doPanning(event, mapView);
break;
case MotionEvent.ACTION_UP:
doPanning(event, mapView);
savedTouchedX = -1;
savedTouchedY = -1;
break;
default:
break;
}
return true;
}
});
...
//move mapView
private boolean doPanning(MotionEvent e, MapView mapView)
{
if(savedTouchedX >= 0 && savedTouchedY >= 0)
{
IGeoPoint mapCenter = mapView.getMapCenter();
GeoPoint panToCenter = new GeoPoint((int)(mapCenter.getLatitudeE6() + (e.getY() - savedTouchedY) * 1E5),
(int)(mapCenter.getLongitudeE6() - (e.getX() - savedTouchedX) * 1E5));
mapView.getController().setCenter(panToCenter);
}
savedTouchedX = e.getX();
savedTouchedY = e.getY();
return true;
}
答案 0 :(得分:1)
基于TouchEvent,以编程方式移动地图
yourFrameLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v , MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
SimpleOnGestureListener listener = new SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1 , MotionEvent e2 , float velocityX , float velocityY) {
float Xdirection = e1.getX() - e2.getX();
float Ydirection = e1.getY() - e2.getY();
//TODO- Do some calculations & change the maps lat & lon.
// Also consider zoom level while calculating.
final double newLat = (getOldLat - (moveSomeLatBasedOnXDirection)));
final double newLon = (getOldLon - (moveSomeLatBasedOnYDirection)));
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng( newLat, newLon));
map.moveCamera(center);
return super.onFling(e1, e2, velocityX, velocityY);
};
};
GestureDetector gestureDetector = new GestureDetector(getActivity(), listener);
答案 1 :(得分:0)
隐藏你的观点。并禁用触摸它。实际上你需要的是什么。
memecontentView.setVisibility(View.GONE);
此节目视图。
memecontentView.setVisibility(View.VISIBLE);
memecontentView.bringToFront();
转移到另一个布局
public void moveView(View view,ViewGroup destination) {
((ViewGroup)view.getParent()).removeView(view);
//Also you can set LayoutParams here
destination.addView(src);
destination.getChildAt(destination.indexOf(src)).bringToFront();
}
用法:
moveView(mapView,yourFrameLayout);
答案 2 :(得分:0)
“我需要用另一张图片覆盖地图”
=>不完全确定了解其他图像应该如何表现。
如果您将其设置为OSMBonusPack GroundOverlay,则会将其绘制在地图上方。地图将对所有事件做出反应(平移,缩放),此上方图像也将根据地图移动进行移动。
如果此上图不应根据地图移动移动,则可以实现新的(但非常简单的)叠加,在mapview上的固定位置绘制图像。它的绘制方法应该是:
@Override protected void draw(Canvas c, MapView mapView, boolean shadow) {
if (shadow)
return;
canvas.drawBitmap(myImage, screenX, screenY, null);
}