在ArcGIS for Android中单击地图时显示图层信息

时间:2013-07-19 06:18:02

标签: android map arcgis

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

私有MapView map = 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);

3 个答案:

答案 0 :(得分:0)

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

在ArcGIS的帮助下,他们解释了如何使用它们以及每个人所做的事情。

这是链接:

Samples ArcGIS Help

希望它有所帮助;)

答案 1 :(得分:0)

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

ArcGIS SDK for Android确实有一个IdentifyTask示例作为Eclipse SDK插件的一部分。安装插件后,在Eclipse中,转到File>新>其他。选择ArcGIS for Android>适用于Android的ArcGIS示例。选中本地样本框,然后选择任务> IdentifyTask。

答案 2 :(得分:0)

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

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(Modue)implementation 'com.esri.arcgisruntime:arcgis-android:100.2.1'

     

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