【问题标题】:Show layer information when cliclked on map in ArcGIS for Android在 ArcGIS for Android 中单击地图时显示图层信息
【发布时间】:2013-07-18 08:06:06
【问题描述】:

最近我开始使用 ArcGIS for Android。在我的应用程序中,我可以使用在 ArcGIS.com 中创建的服务,并且可以在 Android 设备中显示地图。现在我想在单击特定图层时获取地图的图层信息。关于 ArcGIS 资源的信息不多。如果可能的话,如果有人指导我如何通过一些示例获取信息,那将是非常棒的。 显示地图的代码是:

私有 MapView 地图 = null;

String dynamicMapURL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer";

map = (MapView) findViewById(R.id.map);

ArcGISDynamicMapServiceLayer dynamicLayer = new ArcGISDynamicMapServiceLayer(dynamicMapURL); map.addLayer(dynamicLayer);

【问题讨论】:

    标签: android map arcgis


    【解决方案1】:

    您可以使用 ArcGIS API 提供的示例。

    在 ArcGIS 的帮助下,他们解释了如何使用它们以及它们各自的作用。

    这是链接:

    Samples ArcGIS Help

    希望它有所帮助;)

    【讨论】:

      【解决方案2】:

      试试IdentifyTask class。它适用于动态地图服务。

      ArcGIS SDK for Android 有一个IdentifyTask 示例作为Eclipse SDK 插件的一部分。安装插件后,在 Eclipse 中,转到 File > New > Other。选择 ArcGIS for Android > ArcGIS Samples for Android。选中本地示例复选框,然后选择任务 > 识别任务。

      【讨论】:

        【解决方案3】:

        这是使用 ArcGIS-Runtime v100.x Android SDK 在 ArcGIS 地图要素图层上识别和选择对象的简单代码 sn-p。

        MainActivity.java

        import android.graphics.Color;
        import android.os.Bundle;
        import android.support.v7.app.AppCompatActivity;
        import android.util.Log;
        import android.view.MotionEvent;
        import android.widget.Toast;
        
        import com.esri.arcgisruntime.concurrent.ListenableFuture;
        import com.esri.arcgisruntime.data.ArcGISFeature;
        import com.esri.arcgisruntime.data.Feature;
        import com.esri.arcgisruntime.data.FeatureEditResult;
        import com.esri.arcgisruntime.data.FeatureQueryResult;
        import com.esri.arcgisruntime.data.QueryParameters;
        import com.esri.arcgisruntime.data.ServiceFeatureTable;
        import com.esri.arcgisruntime.geometry.Envelope;
        import com.esri.arcgisruntime.geometry.Point;
        import com.esri.arcgisruntime.layers.ArcGISTiledLayer;
        import com.esri.arcgisruntime.layers.FeatureLayer;
        import com.esri.arcgisruntime.mapping.ArcGISMap;
        import com.esri.arcgisruntime.mapping.Basemap;
        import com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener;
        import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
        import com.esri.arcgisruntime.mapping.view.MapView;
        
        import java.util.Iterator;
        import java.util.List;
        import java.util.concurrent.ExecutionException;
        
        public class MainActivity extends AppCompatActivity {
        
            private static final String TAG = "MainActivity";
        
            private MapView mMapView = null;
            private ArcGISMap mMap = null;
        
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                mMapView = findViewById(R.id.mapView);
                mMap = new ArcGISMap();
                mMapView.setMap(mMap);
        
                // Applying base map as tiled layer.
                final Basemap baseMap = new Basemap(new ArcGISTiledLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
                mMap.setBasemap(baseMap);
        
                final ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable("http://..feature-layer-full-url");
                final FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
                featureLayer.setSelectionColor(Color.BLUE);
                featureLayer.setSelectionWidth(10);
                mMap.getOperationalLayers().add(featureLayer);
        
                final GraphicsOverlay overlay = new GraphicsOverlay();
                mMapView.getGraphicsOverlays().add(overlay);
        
                mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
        
                    @Override
                    public boolean onSingleTapConfirmed(MotionEvent event) {
        
                        android.graphics.Point screenPoint = new android.graphics.Point(Math.round(event.getX()), Math.round(event.getY()));
                        Point scenePoint = mMapView.screenToLocation(screenPoint);
        
                        int tolerance = 10;
                        double mapTolerance = tolerance * mMapView.getUnitsPerDensityIndependentPixel();
        
                        // create objects required to do a selection with a query
                        Envelope envelope = new Envelope(scenePoint.getX() - mapTolerance, scenePoint.getY() - mapTolerance, scenePoint.getX() + mapTolerance, scenePoint.getY() + mapTolerance, mMapView.getSpatialReference());
                        QueryParameters query = new QueryParameters();
                        query.setGeometry(envelope);
                        final ListenableFuture<FeatureQueryResult> future = featureLayer.selectFeaturesAsync(query, FeatureLayer.SelectionMode.ADD);
        
                        // add done loading listener to fire when the selection returns
                        future.addDoneListener(new Runnable() {
                            @Override
                            public void run() {
                                try {
        
                                    FeatureQueryResult result = future.get();
                                    Iterator<Feature> iterator = result.iterator();
                                    Feature feature;
                                    int counter = 0;
                                    while (iterator.hasNext()) {
        
                                        feature = iterator.next();
                                        counter++;
                                        Log.d(getResources().getString(R.string.app_name), "Selection #: " + counter + " Table name: " + feature.getFeatureTable().getTableName());
                                    }
        
                                    Toast.makeText(getApplicationContext(), counter + " features selected", Toast.LENGTH_SHORT).show();
        
                                } catch (Exception e) {
        
                                    Log.e(getResources().getString(R.string.app_name), "Select feature failed: " + e.getMessage());
                                }
                            }
                        });
        
                        return true;
                    }
                });
        
            }
        
            @Override
            protected void onPause() {
                mMapView.pause();
                super.onPause();
            }
        
            @Override
            protected void onResume() {
                super.onResume();
                mMapView.resume();
            }
        
            @Override
            protected void onDestroy() {
                super.onDestroy();
                mMapView.dispose();
            }
        
        }
        

        activity_main.xml

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical">
        
            <com.esri.arcgisruntime.mapping.view.MapView
                android:id="@+id/mapView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        
        </LinearLayout>
        

        注意:这在 Android Studio v3.x.x 和 Java 1.8 中可以正常工作。

        build.gradle(模式)implementation 'com.esri.arcgisruntime:arcgis-android:100.2.1'

        build.gradle(项目):maven { 网址'https://esri.bintray.com/arcgis' }

        【讨论】:

          猜你喜欢
          • 2018-07-28
          • 1970-01-01
          • 1970-01-01
          • 2022-06-12
          • 2021-01-20
          • 1970-01-01
          • 1970-01-01
          • 2018-02-24
          • 2012-12-12
          相关资源
          最近更新 更多