arcgis for android MapView点击事件查询

程吕恭
2023-12-01
@Override
    public void addMapViewClickLisenter() {
        mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                ISQS = false;
                ISBJ = false;
                ISXZ = false;
                // if (CLICKABLE) {
                final android.graphics.Point point11 = new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY()));
                final Point center = mMapView.screenToLocation(point11);
                if (center == null) {
                    return super.onSingleTapUp(e);
                }

                final ListenableFuture<List<IdentifyLayerResult>> listListenableFuture = mMapView.identifyLayersAsync(point11, 0, false, 5);
                listListenableFuture.addDoneListener(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            List<IdentifyLayerResult> identifyLayerResults = listListenableFuture.get();
                            int i = 0;
                            int d=identifyLayerResults.size();
                            if(d==1){
                                mBoolean=false;
                                for (IdentifyLayerResult identifyLayerResult : identifyLayerResults) {

                                    SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.YELLOW, 1);
                                    SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, simpleLineSymbol);
                                    Geometry geometry;

                                    for (final GeoElement geoElement : identifyLayerResult.getElements()) {
                                        attributes = geoElement.getAttributes();
                                        Log.e("aaa",attributes.get("DCLY").toString()+"-----aa-----------");
                                        for (Map.Entry<String,Object>M:attributes.entrySet()){
                                            Log.e("aaa",M.getKey()+"");
                                        }
                                        if (graphicsOverlay != null) {
                                            graphicsOverlay.getGraphics().clear();
                                        }

                                        geometry = geoElement.getGeometry();
                                        Graphic graphic = new Graphic(geometry, simpleFillSymbol);
                                        graphicsOverlay = new GraphicsOverlay();
                                        graphicsOverlay.getGraphics().add(graphic);
                                        mMapView.getGraphicsOverlays().add(graphicsOverlay);
                                        Map<String, Object> map = attributes;
                                        for (Map.Entry<String, Object> m : map.entrySet()) {
                                            Log.e("aaa", m.getKey() + "--------" + m.getValue());
                                            for (int a = 0; a < Constant.WAIYE_CHANGE_FEILD.length; a++) {
                                                if (m.getKey().equals(Constant.WAIYE_CHANGE_FEILD[a])) {
                                                    mObjectMap.put(m.getKey(), m.getValue());
                                                    Log.e("aaasss", m.getKey() + "--------" + m.getValue());
                                                    map.remove(Constant.WAIYE_CHANGE_FEILD[a]);
                                                }
                                            }
                                        }
                                        /*Map<String, Object> map1 = new HashMap<>();
                                        for (Map.Entry<String, Object> m : map.entrySet()) {
                                            for (int b = 0; b < mFieldsBeans.size(); b++) {
                                                if (m.getKey().equals(mFieldsBeans.get(b).getName())) {
                                                    if (m.getValue() == null) {
                                                        map1.put(mFieldsBeans.get(b).getAlias(), "");
                                                    } else {
                                                        map1.put(mFieldsBeans.get(b).getAlias(), m.getValue());
                                                    }
                                                }
                                            }
                                        }*/

                                        showLeftPopupWindow();
                                        Log.e("aaa", attributes.size() + "");

                                    }
                                }
                            }else if (d>1){
                                mBoolean=true;
                                //mTuBanType=new ArrayList<>();
                                mListDeafult=new ArrayList<>();
                                mListWaiye=new ArrayList<>();

                                int o=0;
                                for (IdentifyLayerResult identifyLayerResult : identifyLayerResults) {

                                    SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.YELLOW, 1);
                                    SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, simpleLineSymbol);
                                    Geometry geometry;
                                    Map<String,Object>mapsa=new HashMap<>();
                                    Map<String,Object>mapsb=new HashMap<>();
                                    for (final GeoElement geoElement : identifyLayerResult.getElements()) {
                                        mapsa = geoElement.getAttributes();
                                        for (Map.Entry<String,Object>m:mapsa.entrySet()){
                                            Log.e("aaa",m.getKey()+"--------------"+m.getValue()+"");
                                        }
                                        if (graphicsOverlay != null) {
                                            graphicsOverlay.getGraphics().clear();
                                        }
                                        geometry = geoElement.getGeometry();
                                        Graphic graphic = new Graphic(geometry, simpleFillSymbol);
                                        graphicsOverlay = new GraphicsOverlay();
                                        graphicsOverlay.getGraphics().add(graphic);
                                        mMapView.getGraphicsOverlays().add(graphicsOverlay);
                                        Map<String, Object> map = mapsa;
                                        for (Map.Entry<String, Object> m : map.entrySet()) {
                                            Log.e("aaa", m.getKey() + "--------" + m.getValue());
                                            for (int a = 0; a < Constant.WAIYE_CHANGE_FEILD.length; a++) {
                                                if (m.getKey().equals(Constant.WAIYE_CHANGE_FEILD[a])) {
                                                    mapsb.put(m.getKey(), m.getValue());
                                                    map.remove(Constant.WAIYE_CHANGE_FEILD[a]);
                                                }
                                            }
                                        }
                                        mapsb.put("DCLY",mapsa.get("DCLY"));
                                        /*Map<String, Object> map1 = new HashMap<>();
                                        for (Map.Entry<String, Object> m : map.entrySet()) {
                                            for (int b = 0; b < mFieldsBeans.size(); b++) {
                                                if (m.getKey().equals(mFieldsBeans.get(b).getName())) {
                                                    if (m.getValue() == null) {
                                                        map1.put(mFieldsBeans.get(b).getAlias(), "");
                                                    } else {
                                                        map1.put(mFieldsBeans.get(b).getAlias(), m.getValue());
                                                    }
                                                }
                                            }
                                        }*/

//                                        Log.e("aaa", attributes.size() + "");

                                    }
                                    mListDeafult.add(mapsa);
                                    mListWaiye.add(mapsb);

                                    ++o;
                                    if (o==2){
                                        Log.e("aaa","ccccc");
                                        showLeftPopupWindow();
                                    }
                                }




                            }

                        } catch (InterruptedException e) {
                        } catch (ExecutionException e) {
                            e.printStackTrace();
                        }
                    }
                });
                //}
                return super.onSingleTapUp(e);
            }
        });
    }

 

 类似资料: