首页 / 浏览问题 / 移动GIS / 问题详情
对数据集里的点进行模糊查询,定位至该点时天地图和点线数据集都消失,只有图标。
30EXP 2023年07月11日

是代码的问题吗?可以帮忙看看吗

private void getquery(){
        mapView.removeAllCallOut();
        String in=editText.getText().toString().trim();
        if(in.length()==0){
            Toast.makeText(CONTEXT,"请输入名字",Toast.LENGTH_SHORT).show();
        }else {
            Datasource locationDatasource=workspace.getDatasources().get("DATA");
            String query="name like '%" + in + "%'";
            DatasetVector locationdata=(DatasetVector) locationDatasource.getDatasets().get("park_1");
            Recordset recordset = locationdata.query ( query, CursorType.STATIC );
            if(recordset.getRecordCount()>0){
                showRecord(recordset);
                //mapControl.setGestureDetector(new GestureDetector(new MapGestureListener(0)));
            }else {
                DatasetVector locationdata2=(DatasetVector) locationDatasource.getDatasets().get("hospital_1");
                Recordset recordset2 = locationdata2.query ( query, CursorType.STATIC );
                if(recordset2.getRecordCount()>0){
                    showRecord(recordset2);
                    //mapControl.setGestureDetector(new GestureDetector(new MapGestureListener(1)));
                }else {
                    DatasetVector locationdata3=(DatasetVector) locationDatasource.getDatasets().get("WC");
                    Recordset recordset3 = locationdata3.query ( query, CursorType.STATIC );
                    showRecord(recordset3);
                    //mapControl.setGestureDetector(new GestureDetector(new MapGestureListener(2)));
                }
            }
        }
    }

    private void showRecord(Recordset recordset){
        if(recordset.getRecordCount()>0){
            Map getmap=mapView.getMapControl().getMap();
            recordset.moveFirst();
            while (!recordset.isEOF()){
                GeoPoint geoPoint=(GeoPoint) recordset.getGeometry();;
                callout(geoPoint);
                recordset.moveNext();
            }
            if (recordset.getRecordCount()==1){
                recordset.moveFirst();
                GeoPoint geoPoint = (GeoPoint) recordset.getGeometry();
                Point2D point2d = new Point2D(geoPoint.getX(), geoPoint.getY());
                getmap.setCenter(point2d);
                getmap.setScale(1.0 / 50000);
                getmap.refresh();
            }else {
                Rectangle2D rc = recordset.getBounds();
                getmap.setViewBounds(rc);
                getmap.zoom(0.5);
                getmap.refresh();
            }

        }else {
            Toast.makeText(CONTEXT, "没有符合条件的记录,请重新输入", Toast.LENGTH_SHORT).show();
        }
//           recordset.dispose();

    }

    private void callout(GeoPoint geoPoint){
        CallOut callOut=new CallOut(CONTEXT);
        ImageView imageView=new ImageView(CONTEXT);
        imageView.setBackgroundResource(R.drawable.ic_btn_poi);
        callOut.setContentView(imageView);
        callOut.setCustomize(true);
        callOut.setLocation(geoPoint.getX(),geoPoint.getY());
        mapView.addCallout(callOut);
    }
    private void showList(Recordset recordset) {
        if (recordset.getRecordCount() > 0) {
            getResult = new ArrayList<>();
            Map getmap = mapView.getMapControl().getMap();
            recordset.moveFirst();
            while (!recordset.isEOF()) {
                String getGet = recordset.getFieldValue("name").toString();
                getResult.add(getGet);
                recordset.moveNext();
            }
            getR = new String[recordset.getRecordCount()];
            for (int i = 0; i < recordset.getRecordCount(); i++) {
                getR[i] = getResult.get(i);
            }
            listPopupWindow.setAdapter(new ArrayAdapter<String>(CONTEXT, android.R.layout.simple_list_item_1, getR));
            listPopupWindow.setAnchorView(editText);
            listPopupWindow.setModal(false);
            listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    editText.setText(getR[position]);
                    listPopupWindow.dismiss();
                }
            });
            listPopupWindow.show();
        }
    }

    private void showResultList(){
        String in=editText.getText().toString().trim();
        if(in.isEmpty()){

        }else {
            Datasource locationDatasource=workspace.getDatasources().get("DATA");
            String query="name like '%" + in + "%'";
            DatasetVector locationdata=(DatasetVector) locationDatasource.getDatasets().get("park_1");
            Recordset recordset = locationdata.query ( query, CursorType.STATIC );
            if(recordset.getRecordCount()>0){
                showList(recordset);
            }else {
                DatasetVector locationdata2=(DatasetVector) locationDatasource.getDatasets().get("hospital_1");
                Recordset recordset2 = locationdata2.query ( query, CursorType.STATIC );
                if(recordset2.getRecordCount()>0){
                    showList(recordset2);

                }else {
                    DatasetVector locationdata3=(DatasetVector) locationDatasource.getDatasets().get("WC");
                    Recordset recordset3 = locationdata3.query ( query, CursorType.STATIC );
                    showList(recordset3);
                }
            }
        }
    }

1个回答

您好,如果是定位后发生这样的情况,建议查看下定位的位置是否超过了地图的范围,比如使用的经纬度天地图与投影坐标系数据叠加,那么投影坐标系数据集中的对象位置超过了地理坐标系范围就会导致范围超过而数据都看不见了
3,745EXP 2023年07月11日
不太能懂,可以帮忙看一看吗
定位的位置就是数据集的位置,搜索多个相同名字的数据集可以展示,单个数据集不能。数据集和天地图的坐标系都相同。
应该保持使用的数据坐标系一致,而且对象位置都要在坐标系范围之内即正确的有效数据
热门文章
关注我们
...