安卓给arcgismap添加要素点击事件,添加面

直接上代码添加点击事件

        mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(WorkMapQueActivity.this, mapView) {
            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                Point clickPoint = mMapView.screenToLocation(new android
                        .graphics.Point(Math.round(e.getX()), Math.round(e
                        .getY())));
                android.graphics.Point mapPoint = new android.graphics.Point((int) e.getX(), (int) e.getY());
                //将屏幕坐标 传入 identifyGraphicsOverlaysAsync (屏幕坐标,范围,包括图形和弹出窗口时为false,最大检索数)
                final ListenableFuture<List<IdentifyGraphicsOverlayResult>> listListenableFuture = mapView.identifyGraphicsOverlaysAsync(mapPoint, 12, false, 5);
                //添加点击事件
                listListenableFuture.addDoneListener(new Runnable() {
                    @SuppressLint("ClickableViewAccessibility")
                    @Override
                    public void run() {
                        try {
                            //获取点击的范围列表
                            List<IdentifyGraphicsOverlayResult> identifyLayerResults = listListenableFuture.get();
                            //循环图层
                            for (IdentifyGraphicsOverlayResult identifyLayerResult : identifyLayerResults) {
                                //循环所点击要素
                                for (final GeoElement geoElement : identifyLayerResult.getGraphics()) {

                                    try {
                                        Graphic graphic1 = (Graphic) geoElement;
                                        String id = graphic1.getAttributes().get("areaId").toString();
                                        FirstMainActivity.startFirstQueActivity(WorkMapQueActivity.this);
                                    } catch (Exception e) {

                                    }
                                    break;
                                }
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } catch (ExecutionException e) {
                            e.printStackTrace();
                        }
                    }
                });
                return super.onSingleTapConfirmed(e);
            }
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                Point clickPoint = mMapView.screenToLocation(new android
                        .graphics.Point(Math.round(e.getX()), Math.round(e
                        .getY())));

                return super.onSingleTapConfirmed(e);

            }
        });
    }```
在地图上添加要素代码
添加面
        ```Polygon polygon = new Polygon(points);

            SimpleFillSymbol fillSymbol;

            int color = getOverColor(attributesBean.getStatus());
            SimpleLineSymbol outLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, Color.rgb(0, 0, 0), 1);
            fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, color, outLineSymbol);

            Graphic netGraphic = new Graphic(polygon, fillSymbol);
            netGraphic.getAttributes().put("areaId", houseID + "");
            netGraphic.getAttributes().put("zrzid", zrzID + "");
            mapView.getGraphicsOverlays().get(0).getGraphics().add(netGraphic);```
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容