// final String whereClause = "name = "+ "\""+qujie_name+"\"";
final String whereClause = "name like "+ "\'%"+name+"%\'";
QueryParameters query = new QueryParameters();
query.setWhereClause(whereClause);
if (name.length() != 0){
for (GeodatabaseFeatureTable gdbTable : gdbFeatureTables){
final FeatureLayer queryFeatureLayer = gdbTable.getFeatureLayer();
// 查询图层显示
queryFeatureLayer.setVisible(false);
final ListenableFuture<FeatureQueryResult> featureQueryResult = queryFeatureLayer.selectFeaturesAsync(query,FeatureLayer.SelectionMode.SUBTRACT);
featureQueryResult.addDoneListener(new Runnable() {
@Override
public void run() {
try {
FeatureQueryResult features = featureQueryResult.get();
for (Object element : features){
if (element instanceof Feature){
mFeature = (Feature) element;
// 查询图层显示
queryFeatureLayer.setVisible(true);
// 筛选要素图层
queryFeatureLayer.setDefinitionExpression(whereClause);
// 高亮
queryFeatureLayer.selectFeature(mFeature);
// 取消高亮
//queryFeatureLayer.unselectFeature(mFeature);
Geometry geometry = mFeature.getGeometry();
// 点 定位 - 固定比例尺
// mapView.setViewpointCenterAsync((Point) geometry,500);
// 图形定位 - 自定义比例尺
mapView.setViewpointGeometryAsync(geometry);
/* Graphic graphic = null;
if (geometry.getGeometryType() == GeometryType.POINT){// 点
Point point = (Point) geometry;
SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE,Color.RED,8);
// 渲染
SimpleRenderer simpleRenderer = new SimpleRenderer(simpleMarkerSymbol);
mGraphicsOverlay.setRenderer(simpleRenderer);
graphic = new Graphic(point);
mGraphicsOverlay.getGraphics().add(graphic);
}else if(geometry.getGeometryType() == GeometryType.POLYLINE){// 线
Polyline polyline = (Polyline) geometry;
SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID,Color.GREEN,2);
graphic = new Graphic(polyline,simpleLineSymbol);
mGraphicsOverlay.getGraphics().add(graphic);
}else if (geometry.getGeometryType() == GeometryType.POLYGON){// 面
Polygon polygon = (Polygon) geometry;
SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID,Color.BLUE,2);
graphic = new Graphic(polygon,simpleLineSymbol);
mGraphicsOverlay.getGraphics().add(graphic);
}*/
}
}
}catch (Exception ex){
ex.printStackTrace();
}
}
});
}
}
|