我是使用ArcGIS android runtime API开发android应用程序的新手。

我正在尝试扩大范围,并强调这一范围。但这对我来说不起作用。


  功能层网址为https://services7.arcgis.com/7FyZZrSIYfiWYztL/ArcGIS/rest/services/MyGisFileTest/FeatureServer/0


这是从ArcGIS在线门户获得的。
我已经在地图上添加了图层

ArcGISFeatureLayer fl1 = new ArcGISFeatureLayer(
                "https://services7.arcgis.com/7FyZZrSIYfiWYztL/ArcGIS/rest/services/MyGisFileTest/FeatureServer/0",
                ArcGISFeatureLayer.MODE.ONDEMAND);
        fl1.setOnStatusChangedListener(statusChangedListener);
mMapView.addLayer(fl1);


在这里,我通过使用edittext从用户输入中获取ward_name,并将其提交给asyn类以获取数据。

我在单击按钮时调用同步任务,并将用户输入的值传递给异步任务。

申报部分

//query task
private Callout mCallout;
private ViewGroup mCalloutContent;
private Graphic mIdentifiedGraphic;
private String mFeatureServiceURL;
private GraphicsLayer mGraphicsLayer;
private ProgressDialog progress;
EditText _EdtTxtTextToZoom;
Button _BtnZoomToExtend;


在我的oncreate方法中,我定义了所有东西

mGraphicsLayer = new GraphicsLayer();
        mMapView.addLayer(mGraphicsLayer);
        LayoutInflater inflater = getLayoutInflater();
        mCallout = mMapView.getCallout();
        // Get the layout for the Callout from
        // layout->identify_callout_content.xml
        mFeatureServiceURL="https://services7.arcgis.com/7FyZZrSIYfiWYztL/ArcGIS/rest/services/MyMapService/FeatureServer/0";
        mCalloutContent = (ViewGroup) inflater.inflate(R.layout.identify_callout_content, null);
        mCallout.setContent(mCalloutContent);
        mIdentifiedGraphic = getFeature(fl1);
        _EdtTxtTextToZoom=(EditText)findViewById(R.id.EdtTxtTextToZoom);
        _BtnZoomToExtend=(Button)findViewById(R.id.BtnZoomToExtend);
        _BtnZoomToExtend.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                String tempEdtTxtTextToZoom= "";
                try {
                    tempEdtTxtTextToZoom = _EdtTxtTextToZoom.getText().toString();
                    new QueryFeatureLayer().execute(tempEdtTxtTextToZoom);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
                Toast.makeText(MainActivity.this, "tempEdtTxtTextToZoom.."+tempEdtTxtTextToZoom, Toast.LENGTH_SHORT).show();
            }
        });


异步任务

private class QueryFeatureLayer extends AsyncTask<String, Void, FeatureResult> {

        // default constructor
        public QueryFeatureLayer() {
        }

        @Override
        protected void onPreExecute() {
            progress = ProgressDialog.show(MainActivity.this, "", "Please wait....query task is executing");
        }

        @Override
        protected FeatureResult doInBackground(String... params) {
            Log.e("params[0]--",params[0]);
            String whereClause = "ward_name ='" + params[0] + "'";
            Log.e("whereClause--",whereClause);
            // Define a new query and set parameters
            QueryParameters mParams = new QueryParameters();
            mParams.setWhere(whereClause);
            mParams.setReturnGeometry(true);

            // Define the new instance of QueryTask
            QueryTask queryTask = new QueryTask(mFeatureServiceURL);
            FeatureResult results;

            try {
                // run the querytask
                results = queryTask.execute(mParams);
                Log.e("results---", String.valueOf(results));
                return results;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(FeatureResult results) {

            // Remove the result from previously run query task
            mGraphicsLayer.removeAll();

            // Define a new marker symbol for the result graphics
            SimpleMarkerSymbol mGreenMarkerSymbol = new SimpleMarkerSymbol(Color.GREEN, 15, SimpleMarkerSymbol.STYLE.CIRCLE);

            // Envelope to focus on the map extent on the results
            Envelope extent = new Envelope();

            // iterate through results
            for (Object element : results) {
                // if object is feature cast to feature
                if (element instanceof Feature) {
                    Feature feature = (Feature) element;
                    // convert feature to graphic
                    Graphic graphic = new Graphic(feature.getGeometry(), mGreenMarkerSymbol, feature.getAttributes());
                    // merge extent with point
                    extent.merge((Point)graphic.getGeometry());
                    Log.e("points----", String.valueOf(graphic.getGeometry()));
                    // add it to the layer
                    mGraphicsLayer.addGraphic(graphic);
                }
            }
            Log.e("points----", String.valueOf(extent));
            // Set the map extent to the envelope containing the result graphics
            mMapView.setExtent(extent, 100);
            // Disable the progress dialog
            progress.dismiss();

        }
    }


你能弄清楚我在哪里做错了吗?

最佳答案

在上面的示例中,我尝试缩放点,但实际上我想要多边形以下是缩放特定多边形范围的正确代码

            for (Object element : results) {
                progress.incrementProgressBy(size / 100);
                if (element instanceof Feature) {
                    Feature feature = (Feature) element;

                    // turn feature into graphic
                    Graphic graphic = new Graphic(feature.getGeometry(),
                            feature.getSymbol(), feature.getAttributes());
                    Polygon p = (Polygon) graphic.getGeometry();
                    p.queryEnvelope(extent);
                    extent.merge(extent);

                    // add graphic to layer
                    mGraphicsLayer.addGraphic(graphic);

关于java - ARCGIS Android无法从querytask结果获取扩展,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44157953/

10-09 07:56