1.获取featureLayer图层
(1)在线获取
ServiceFeatureTable mServiceFeatureTable = new ServiceFeatureTable("feature_service_url");
mServiceFeatureTable.setFeatureRequestMode(ServiceFeatureTable.FeatureRequestMode.ON_INTERACTION_CACHE);
FeatureLayer mFeatureLayer = new FeatureLayer(mServiceFeatureTable);
(2)离线获取
// gdbPath -- .geodatabase文件存储路径
mGeodatabase = new Geodatabase(gdbPath);
mGeodatabase.loadAsync();// 异步加载(必须写)
mGeodatabase.addDoneLoadingListener(new Runnable() {
@Override
public void run() {
gdbFeatureTables = mGeodatabase.getGeodatabaseFeatureTables();
// 图例List
legendListMap = new ArrayList<>();
for (GeodatabaseFeatureTable gdbTable : gdbFeatureTables) {
FeatureLayer featureLayer = new FeatureLayer(gdbTable);
// 要素图层名称
String featureName = featureLayer.getName();
// 要素图层添加到地图上
mapView.getMap().getOperationalLayers().add(featureLayer);
}
}
});
2.执行featureLayer.fetchLegendInfosAsync();方法,获取图例信息
Bitmap bitmap = null;
ListenableFuture<List<LegendInfo>> listenableFuture = featureLayer.fetchLegendInfosAsync();
try {
List<LegendInfo> legendInfoList = listenableFuture.get();
for (LegendInfo legendInfo: legendInfoList) {
/**
* 该方法拥有多个构造方法
* 1. createSwatchAsync(int width, int height, float screenScale, int backgroundColor)
* 2. createSwatchAsync(Context context, int backgroundColor)
* 3. createSwatchAsync(int backgroundColor, float screenScale)
* 4. createSwatchAsync(int width, int height, float screenScale, int backgroundColor, Geometry geometry)
* */
ListenableFuture<Bitmap> bitmapListenableFuture = legendInfo.getSymbol().createSwatchAsync(Color.WHITE, 3);
bitmap = bitmapListenableFuture.get();
}
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}