android QueryService setQueryGeomety 无效 [已关闭]

0 投票
/**
     * 查询服务类
     */
    public void ServiceQuery() {

        //假设http://192.168.170.59:8090地址服务器上已发布地图Rest服务,服务名称为map-testmap/rest,该地图服务中包含地图map,地图中含有 图层Capitals@testmap。
        QueryService service = new QueryService("");
        ServiceQueryParameter parameter = new ServiceQueryParameter();
        parameter.setQueryMapName("Map2");//地图名称
        parameter.setQueryServiceName("map-wk2D2/rest");//服务名称
        parameter.setQueryLayerName("WS_2DPOINT@ds2D2");//图层名称
        //parameter.setQueryLayerName("YS_2DPOINT@ds2D2");

        Point2D point2D=new Point2D(X-0.000005,Y-0.000005);
        Point2D point2D2=new Point2D(X+0.000005,Y-0.000005);

        Point2D point2D3=new Point2D(X+0.000005,Y+0.000005);

        Point2D point2D4=new Point2D(X-0.000005,Y-0.000005);

        Point2D[] point2DS={point2D,point2D2,point2D3,point2D4};

        Point2Ds point2Ds=new Point2Ds(point2DS);

        GeoRegion geoRegion=new GeoRegion(point2Ds);

        parameter.setQueryGeomety(geoRegion);//无效

        parameter.setExpectRecordCount(1);//计划返回服务查询个数
        parameter.setQueryRecordStart(0);//设置查询记录的起始位置
        parameter.setQueryOption(QueryOption.ATTRIBUTEANDGEOMETRY);//设置查询结果内容类型。
//        parameter.setQueryDistance(1);
//        parameter.setAttributeFilter("SMID>0");//设置查询的SQL条件语句。
        parameter.setSpatialQueryMode(SpatialQueryMode.INTERSECT);

        service.setResponseCallback(new ResponseCallback() {

            @Override
            public void requestSuccess() {
                // TODO Auto-generated method stub
                Log.i("ResponseCallback","查询requestSuccess");
            }

            @Override
            public void addFeatureSuccess(int i) {
                Log.i("ResponseCallback","addFeatureSuccess"+i);
            }

            @Override
            public void requestFailed(String arg0) {
                // TODO Auto-generated method stub
                Log.e("ResponseCallback","查询requestFailed:"+arg0);
            }

            @Override
            public void receiveResponse(FeatureSet arg0) {
                Log.i("ResponseCallback","receiveResponse:"+arg0);
                if (arg0 instanceof FeatureSet) {
                    FeatureSet featureSet = (FeatureSet)arg0;
                    FieldInfos fieldInfos=featureSet.getFieldInfos();
                    featureSet.moveFirst();
                    while (!featureSet.isEOF()) {
                        Geometry geo = featureSet.getGeometry();
                        if (geo == null) {
                            featureSet.moveNext();
                            continue;
                        }
                        Log.i("ResponseCallback","区域的字段个数:count:"+fieldInfos.getCount());
                        for (int i=0;i<fieldInfos.getCount();i++){
                            Object value= featureSet.getFieldValue(fieldInfos.get(i).getName());
                            Log.i("ResponseCallback","name:"+fieldInfos.get(i).getName()+"-----value:"+value.toString());
                        }
                        featureSet.moveNext();
                    }
                    Log.i("ResponseCallback","要素集合中要素的个数是 " + featureSet.getFeatureCount());
                }
            }

            @Override
            public void dataServiceFinished(String s) {
                Log.i("ResponseCallback","dataServiceFinished"+s);
            }
        });
        service.query(");
    }
  private void getPoints(MotionEvent event){
        Toast.makeText(MainActivity.this,"长按事件",Toast.LENGTH_SHORT).show();
        float x=event.getX();
        float y=event.getY();
        Point2D point2D=m_mapcontrol.getMap().pixelToMap(new com.supermap.data.Point((int)x,(int)y));
//        CallOut callOut = new CallOut(context);
//        callOut.setStyle(CalloutAlignment.BOTTOM);
//        final View view = LayoutInflater.from(
//                context).inflate(
//                R.layout.callout, null);
        Log.i("getPoints","X:"+point2D.getX()+"Y:"+point2D.getY());
        X=point2D.getX();
        Y=point2D.getY();

        ServiceQuery();
//        callOut.setContentView(view);
//        callOut.setCustomize(true);
//        callOut.setLocation(point2D.getX(), point2D.getY());
//        mapView.addCallout(callOut);
//        Toast.makeText(context, "x="+point2D.getX()+" y="+point2D.getY(), Toast.LENGTH_SHORT).show();
//        System.out.println("x="+point2D.getX()+" y="+point2D.getY());
//        mapControl.getMap().refresh();
    }

设置

parameter.setQueryGeomety(geoRegion);无效 始终返回了图层的所有信息 并不是返回的我所点击的x y的信息
问题关闭原因: 已解决
6月 8 分类:  26次浏览 | 用户: 曹半斤 (9 分)
已关闭 6月 8 用户:曹半斤

1个回答

0 投票
您好,这个方法是根据你的查询模式来设置的,如果设置查询模式为SQL查询,这个方法就会无效。如果是需要使用范围查询或者空间查询,设置方法就起效
6月 8 用户: 董懿鑫 登峰造极 (5,722 分)
parameter.setSpatialQueryMode(SpatialQueryMode.INTERSECT);

我设置的是空间查询啊
...