ArcGIS Runtime sdk for Android为我们提供了丰富的事件监听器,本节将主要介绍我们经常使用的监听器,并且介绍通过这些监听器可以实现哪些功能,在下面的监听器中只有MapOnTouchListener是类,其他皆为接口类型,如图所示:
1.1 MapOnTouchListener
- myListener
= new MyTouchListener(this, mapView); -
mapView.setOnTouchListener(myListener); -
-
class MyTouchListener extends MapOnTouchListener { -
-
public MyTouchListener(Context context, MapView view) { -
super(context, view); -
} -
public void setType(String geometryType) { -
this.type = geometryType; -
} -
public String getType() { -
return this.type; -
} -
public boolean onSingleTap(MotionEvent e) { -
return true; -
} -
public boolean onDragPointerMove(MotionEvent from, MotionEvent to) { -
return super.onDragPointerMove(from, to); -
} -
@Override -
public boolean onDragPointerUp(MotionEvent from, MotionEvent to) { -
return super.onDragPointerUp(from, to); -
} -
}
1.2 OnLongPressListener
- //为地图添加一个长按监听器
- mapView.setOnLongClickListener(new
View.OnLongClickListener() { -
//长按后自动执行的方法 -
public boolean onLongClick(View v) { -
// TODO Auto-generated method stub -
return false; -
} -
});
1.3 OnPanListener
- //为地图添加一个平移监听器
- mapView.setOnPanListener(new
OnPanListener() { -
public void prePointerUp(float fromx, float fromy, float tox, float toy) { -
} -
public void prePointerMove(float fromx, float fromy, float tox, float toy) { } -
-
public void postPointerUp(float fromx, float fromy, float tox, float toy) { } -
- public
void postPointerMove(float fromx, float fromy, float tox, float toy) { -
} -
});
1.4 OnPinchListener
- //为地图添加夹/捏监听器
- mapView.setOnPinchListener(new
OnPinchListener() { -
public void prePointersUp(float x1, float y1, float x2, float y2, -
double factor) { -
} -
public void prePointersMove(float x1, float y1, float x2, float y2, -
double factor) { -
} -
public void prePointersDown(float x1, float y1, float x2, float y2, -
double factor) { -
} -
public void postPointersUp(float x1, float y1, float x2, float y2, -
double factor) { -
} -
public void postPointersMove(float x1, float y1, float x2, float y2, -
double factor) { -
} -
public void postPointersDown(float x1, float y1, float x2, float y2, -
double factor) { -
} -
});
1.5 OnSingleTapListener
- //为地图添加单击事件监听
- mapView.setOnSingleTapListener(new
OnSingleTapListener() { -
//点击地图后自动执行的方法 -
public void onSingleTap(float x, float y) { -
// TODO Auto-generated method stub -
-
} -
});
1.6 OnStatusChangedListener
- //添加状态监听器
- mapView.setOnStatusChangedListen
er(new OnStatusChangedListener() { -
public void onStatusChanged(Object source, STATUS status) { -
if(status == STATUS.INITIALIZED){ -
}else if(status == STATUS.LAYER_LOADED){ -
}else if((status == STATUS.INITIALIZATION_FAILED)){ -
}else if((status == STATUS.LAYER_LOADING_FAILED)){ -
} -
} -
});
1)
2)
3)
4)
1.7 OnZoomListener
- mapView.setOnZoomListener(new
OnZoomListener() { -
//缩放之前自动调用的方法 -
public void preAction(float pivotX, float pivotY, double factor) { -
} -
//缩放之后自动调用的方法 -
public void postAction(float pivotX, float pivotY, double factor) { -
} -
});