查询所有要素
ServiceFeatureTable table = new ServiceFeatureTable("url");
FeatureLayer layer = new FeatureLayer(table);
private void query1(FeatureLayer layer, ServiceFeatureTable t){
Envelope envelope = layer.getFeatureTable().getExtent();
parameters.setGeometry(envelope);
mapView.setViewpointGeometryAsync(envelope, 20);
ListenableFuture<FeatureQueryResult> future = t.queryFeaturesAsync(parameters, ServiceFeatureTable.QueryFeatureFields.LOAD_ALL);
future.addDoneListener(() -> {
try {
for (Feature feature: future.get()) {
Log.e("----------->", feature.getAttributes().toString());
Map<String , Object> maps = feature.getAttributes();
for (String key: maps.keySet()) {
Log.e(" " + key, maps.get(key) + "");
}
}
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
});
}
private void query2(FeatureLayer layer){ ? ? ? ? Envelope envelope = layer.getFeatureTable().getExtent(); ? ? ? ? parameters.setGeometry(envelope); ? ? ? ? FeatureTable table = layer.getFeatureTable(); ? ? ? ? mapView.setViewpointGeometryAsync(envelope, 20); ? ? ? ? ListenableFuture<FeatureQueryResult> future = table.queryFeaturesAsync(parameters); ? ? ? ? future.addDoneListener(() -> { ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? for (Feature feature: future.get()) { ? ? ? ? ? ? ? ? ? ? Log.e("----------->", feature.getAttributes().toString()); ? ? ? ? ? ? ? ? ? ? Map<String , Object> maps = feature.getAttributes(); ? ? ? ? ? ? ? ? ? ? for (String key: maps.keySet()) { ? ? ? ? ? ? ? ? ? ? ? ? Log.e(" ?" + key, maps.get(key) + ""); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } catch (ExecutionException | InterruptedException e) { ? ? ? ? ? ? ? ? e.printStackTrace(); ? ? ? ? ? ? } ? ? ? ? }); ? ? }
查询所有要素并高亮
private void query(FeatureLayer layer){
Envelope envelope = layer.getFeatureTable().getExtent();
parameters.setGeometry(envelope);
ListenableFuture<FeatureQueryResult> future = layer.selectFeaturesAsync(parameters, FeatureLayer.SelectionMode.NEW);
future.addDoneListener(() -> {
try {
Log.e("--------->", future.get() + "");
for (Feature feature: future.get()) {
Map<String , Object> maps = feature.getAttributes();
for (String key: maps.keySet()) {
Log.e(" " + key, maps.get(key) + "");
}
}
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
});
}
点击查询
mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mapView){
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
point = new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY()));
ListenableFuture<List<IdentifyLayerResult>> future =
mapView.identifyLayersAsync(point, 15.0, false, -1);
future.addDoneListener(() -> {
try {
Log.e("---总图层数->", future.get().size() + "");
for (IdentifyLayerResult result: future.get()) {
Log.e("---z长度->", "弹窗 " + result.getPopups().size() + " -元素 " + result.getElements().size()
+ " -图层 " + result.getSublayerResults().size());
Log.e("---地图names->", result.getLayerContent().getName());
for (LayerContent content: result.getLayerContent().getSubLayerContents()) {
Log.e("---地图name->", content.getName());
}
// for (IdentifyLayerResult layerResult: result.getSublayerResults()) {
// for (int i = 0; i < layerResult.getElements().size(); i++) {
// GeoElement element = layerResult.getElements().get(i);
//
// Map<String, Object> map = element.getAttributes();
// for (String key: map.keySet()) {
// Log.e("Sublayer--> " + key, map.get(key) + "");
// }
// Log.e("--" + i + "--Sublayer--几何形状->", element.getGeometry().toJson());
//
// }
// }
for (int i = 0; i < result.getElements().size(); i++) {
GeoElement element = result.getElements().get(i);
Map<String, Object> map = element.getAttributes();
for (String key: map.keySet()) {
Log.e("Elements--> " + key, map.get(key) + "");
}
Log.e("--" + i + "--Elements--几何形状->", element.getGeometry().toJson());
Envelope envelope = element.getGeometry().getExtent();
// query(envelope);
}
}
} catch (ExecutionException | InterruptedException executionException) {
executionException.printStackTrace();
}
});
return super.onSingleTapConfirmed(e);
}
});
|