直接上代码添加点击事件
mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(WorkMapQueActivity.this, mapView) {
@Override
public boolean onSingleTapUp(MotionEvent e) {
Point clickPoint = mMapView.screenToLocation(new android
.graphics.Point(Math.round(e.getX()), Math.round(e
.getY())));
android.graphics.Point mapPoint = new android.graphics.Point((int) e.getX(), (int) e.getY());
//将屏幕坐标 传入 identifyGraphicsOverlaysAsync (屏幕坐标,范围,包括图形和弹出窗口时为false,最大检索数)
final ListenableFuture<List<IdentifyGraphicsOverlayResult>> listListenableFuture = mapView.identifyGraphicsOverlaysAsync(mapPoint, 12, false, 5);
//添加点击事件
listListenableFuture.addDoneListener(new Runnable() {
@SuppressLint("ClickableViewAccessibility")
@Override
public void run() {
try {
//获取点击的范围列表
List<IdentifyGraphicsOverlayResult> identifyLayerResults = listListenableFuture.get();
//循环图层
for (IdentifyGraphicsOverlayResult identifyLayerResult : identifyLayerResults) {
//循环所点击要素
for (final GeoElement geoElement : identifyLayerResult.getGraphics()) {
try {
Graphic graphic1 = (Graphic) geoElement;
String id = graphic1.getAttributes().get("areaId").toString();
FirstMainActivity.startFirstQueActivity(WorkMapQueActivity.this);
} catch (Exception e) {
}
break;
}
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
});
return super.onSingleTapConfirmed(e);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Point clickPoint = mMapView.screenToLocation(new android
.graphics.Point(Math.round(e.getX()), Math.round(e
.getY())));
return super.onSingleTapConfirmed(e);
}
});
}```
在地图上添加要素代码
添加面
```Polygon polygon = new Polygon(points);
SimpleFillSymbol fillSymbol;
int color = getOverColor(attributesBean.getStatus());
SimpleLineSymbol outLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, Color.rgb(0, 0, 0), 1);
fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, color, outLineSymbol);
Graphic netGraphic = new Graphic(polygon, fillSymbol);
netGraphic.getAttributes().put("areaId", houseID + "");
netGraphic.getAttributes().put("zrzid", zrzID + "");
mapView.getGraphicsOverlays().get(0).getGraphics().add(netGraphic);```