首页 > 代码库 > arcgis andriod 点击后变色

arcgis andriod 点击后变色

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent">    <com.esri.android.map.MapView        android:id="@+id/map"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        url="http://www.arcgis.com/home/webmap/viewer.html?webmap=fab9925c7c974a0aa47ea0f463535367" >    </com.esri.android.map.MapView></RelativeLayout>

java

package yanlei.example.com.querydata;import android.graphics.Color;import android.os.AsyncTask;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import com.esri.android.map.GraphicsLayer;import com.esri.android.map.MapView;import com.esri.android.map.event.OnSingleTapListener;import com.esri.android.map.event.OnStatusChangedListener;import com.esri.core.geometry.Point;import com.esri.core.geometry.SpatialReference;import com.esri.core.map.Feature;import com.esri.core.map.FeatureResult;import com.esri.core.map.Graphic;import com.esri.core.renderer.SimpleRenderer;import com.esri.core.symbol.SimpleFillSymbol;import com.esri.core.tasks.query.QueryParameters;import com.esri.core.tasks.query.QueryTask;public class MainActivity extends AppCompatActivity {    MapView mMapView;    GraphicsLayer graphicsLayer;    Graphic fillGraphic;    String queryLayer;    boolean boolQuery = true;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mMapView = (MapView) findViewById(R.id.map);        queryLayer = "http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Average_Household_Size/MapServer/3";        mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {            private static final long serialVersionUID = 1L;            @Override            public void onStatusChanged(Object source, STATUS status) {                // TODO Auto-generated method stub                if (source == mMapView && status == STATUS.INITIALIZED) {                    graphicsLayer = new GraphicsLayer();                    SimpleRenderer sr = new SimpleRenderer(                            new SimpleFillSymbol(Color.RED));                    graphicsLayer.setRenderer(sr);                    mMapView.addLayer(graphicsLayer);                }            }        });        mMapView.setOnSingleTapListener(new OnSingleTapListener() {            private static final long serialVersionUID = 1L;            @Override            public void onSingleTap(float x, float y) {                // TODO Auto-generated method stub                AsyncQueryTask ayncQuery = new AsyncQueryTask();                ayncQuery.execute(x, y);            }        });    }    private class AsyncQueryTask extends AsyncTask<Float, Void, FeatureResult> {        @Override        protected FeatureResult doInBackground(Float... queryArray) {            // TODO Auto-generated method stub            if (queryArray == null || queryArray.length <= 1)                return null;            float x = queryArray[0];            float y = queryArray[1];            Point point = mMapView.toMapPoint(x, y);            QueryParameters qParameters = new QueryParameters();            SpatialReference sr = SpatialReference.create(102100);            qParameters.setGeometry(point);            qParameters.setOutSpatialReference(sr);            qParameters.setReturnGeometry(true);            QueryTask qTask = new QueryTask(queryLayer);            try {                FeatureResult results = qTask.execute(qParameters);                return results;            } catch (Exception e) {                e.printStackTrace();            }            return null;        }        @Override        protected void onPostExecute(FeatureResult results) {            if (results != null) {                for (Object element : results) {                    if (element instanceof Feature) {                        Feature feature = (Feature) element;                        // turn feature into graphic                        Graphic graphic = new Graphic(feature.getGeometry(),                                feature.getSymbol(), feature.getAttributes());                        // add graphic to layer                        graphicsLayer.removeAll();                        graphicsLayer.addGraphic(graphic);                    }                }            }        }    }    @Override    protected void onPause() {        super.onPause();        mMapView.pause();    }    @Override    protected void onResume() {        super.onResume();        mMapView.unpause();    }}

 

arcgis andriod 点击后变色