如何在Android中查看ArcGIS图层图例?

时间:2017-08-18 04:43:11

标签: android arcgis

我的ArcGIS Feature Server中有3层(Drainage,Bridge和Slope)。我的Android应用查看ArcGISmap上的每个图层,并根据复选框勾选设置图层可见性。我使用的是ArcGIS Runtime SDK for Android(版本100.1)。

我的问题是,是否可以从要素服务器查看图层的图例到我的图层对话框?意味着要取代3个可爱的图标。

Android应用程序(中间的图层对话框)

enter image description here

要素服务器(左侧图层的图例)

enter image description here

提前谢谢!

更新

感谢falldownhill's suggestion使用Create Swatch!这是我的工作代码

// Loop each layer
for (int x=0; x<featureLayer.length; x++)
{
    try
    {
        // Try get each layer legend
        final ListenableFuture<List<LegendInfo>> layerLegend = featureLayer[x].fetchLegendInfosAsync();

        final int finalX = x;
        layerLegend.addDoneListener(new Runnable()
        {
            @Override
            public void run()
            {
                try
                {
                    // Get each layer legend
                    List<LegendInfo> legendInfo = layerLegend.get();
                    Symbol legendSymbol = legendInfo.get(0).getSymbol();
                    ListenableFuture<Bitmap> symbolSwatch = legendSymbol.createSwatchAsync(MainActivity.this, Color.TRANSPARENT);

                    // Set each layer legend
                    Bitmap symbolBitmap = symbolSwatch.get();
                    ImageView swatchImg = (ImageView) drawerDialog.findViewById(layerImageViewId[finalX]);
                    swatchImg.setImageBitmap(symbolBitmap);
                }
                catch (InterruptedException e)
                {
                    //showMessage("Animation interrupted");
                }
                catch (ExecutionException e)
                {
                    // Deal with exception during animation...
                }
            }
        });
    }
    catch (Exception e)
    {
        // Ignore changing layer legend
    }
}

Android应用程序(更新了中间所需图例的图层对话框)

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为Create Swatch会做你正在寻找的事情。

只是为了展示一种使用它的方法:

float density = InstrumentationRegistry.getContext().getResources().getDisplayMetrics().density;
for (FeatureType type : featureTable.getFeatureTypes()) {
  for (FeatureTemplate template : type.getTemplates()) {
    Geometry geometry = //create whatever shape you want the swatch to be
    Feature feature = featureTable.createFeature(template, geometry);
    Symbol symbol = featureLayer.getRenderer().getSymbol(feature);
    ListenableFuture<Bitmap> symbolSwatch = symbol.createSwatchAsync(24, 24,
        density,color,feature.getGeometry());

    Bitmap swatch = symbolSwatch.get();
  }
}