|
大家好,今天从两个版本(arcgis for android beta和arcgis for android2.0)写一下arcgis for android的点击GraphicsLayer如何找到已经添加到GraphicsLayer上面对应的Graphic,从而显示出对应Graphic的信息内容,
本人从arcgis for android beta开始学习使用到arcgis for android2.0,经过了1.0,1.1,..等等,目前使用2.0开发,相对来说2.0是比较稳定的,相对比较,两个版本过渡时期去掉了许多功能,新版本相对更加稳定,功能更强大,废话不多说,上代码:
public OnTouchListener onClick() {
return new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
float x = (float) event.getX();
float y = (float) event.getY();
Graphic[] gs = photoPointGraphicsLayer.getGraphics(x, y, 20);
int count = gs.length;
if (count > 0) {
picAbsolutePath = "";
Point p = null;
try {
picAbsolutePath = gs[0].getAttributeValue("PATH").toString();
p = (Point) gs[0].getAttributeValue("POINT");
} catch (Exception e) {
}
mapCallout.setMaxHeight(190);
mapCallout.setMaxWidth(160);
if (p != null){
showPhoto.setImageURI(Uri.parse(picAbsolutePath));
mapCallout.show(p, mapCalloutView);
}
return true;
}
return false;
}
};
}
arcgis for android beta版sdk,使用时对于我开发时来讲很多是有用的,比如说:GraphicsLayer可以添加List<Graphic>,GraphicsLayer可以单独的注册单击事件,很多有用的方法和类,上面的代码可以直接注册到一个GraphicsLayer,点击GraphicsLayer可以得到MotionEvent也就是手指点中的点X和Y20范围内的所有Graphic,然后使用Callout来显示出来,,使用起来也非常的方便,查找的速度也不错.但是beta版本也有很多方面的不足,不支持离线地图,地图加载速度非常慢,莫明其妙的错误等等.后来过渡到arcgis
for android 1.0,很多方法都被阉割掉了,拿arcgis for android V2 来讲,实现同样的功能应该怎么写呢:代码如下:
public void onLongPress(float x, float y) {
int[] ids=photoPointGraphicsLayer.getGraphicIDs(x, y, 20);
if(ids.length>0){
Graphic graphic=photoPointGraphicsLayer.getGraphic(ids[0]);
picAbsolutePath = "";
Point p = null;
try {
//Map<String,Object> map=graphic.getAttributes();
picAbsolutePath = graphic.getAttributeValue("PATH").toString();
p = new Point(Double.parseDouble(graphic.getAttributeValue("X").toString()),Double.parseDouble(graphic.getAttributeValue("Y").toString()));
mapCallout.setMaxHeight(500);
mapCallout.setMaxWidth(700);
if (p != null){
showPhoto.clearAnimation();
showPhoto.setImageURI(Uri.parse(picAbsolutePath));
mapCallout.show(p, mapCalloutView);
}
} catch (Throwable e) {
e.getMessage();
}
}
}
V2的GraphicsLayer的onTouchListener已经去掉,所以没有办法对其添加事件,唯一的方法就是将事件添加给MapView,我用的是mapView.setOnLongPressListener();对于已经添加到GraphicsLayer来进行查找,然后显示对应的Graphic信息,.这样就实现同样的功能,总的来说,还是很方便的.
谢谢 |