关于 ArcGIS Runtime SDK for Android 10.2.9 中的地物点击事件

目录

1.关于 onSingleTap(float x, float y) 方法

2.识别地图上的 marker graphic

3.识别地图上的 Geometry Feature

4.需要注意的点

1.点击事件之前

2.加载离线 .shp 文件

3. 处理 FeatureLayer 中没有要素的情况

4.居中地物

5.关于 Fragment 或者 Activity 中的 MapView


在 ArcGIS Runtime SDK for Android 10.2.9 中,并没有专门针对 marker 和其他地物点击事件监听,需要我们自己在为地图设置单击监听,并在 onSingleTap 方法中自己处理。

1.关于 onSingleTap(float x, float y) 方法

首先让持有 MapView 控件的 Activity 或者 Fragment 实现 OnSingleTapListener,需要注意的是该接口中的 onSingleTap(float x, float y) 中的 x、y 是屏幕坐标 x、y,如果你需要地图上的 Geometry 类型的 point ,可以使用下列方法来得到地图上的点:

Point mapPoint = mMapView.toMapPoint(x, y);

2.识别地图上的 marker graphic

在加载图层时,一般 marker (标识建筑或者地理位置的图片)是位于最上层的 GraphicsLayer 中,所以最先接收点击事件的应该是 marker,之后才是 FeatureLayer 等其他图层来处理。

在 GraphicsLayer 中,有一个方法来获取 Graphic 要素:

public Graphic getGraphic(int uid) {
    ...
}

那么我们首先要获取 uid 即 graphicId,通过如下方法:

    public int[] getGraphicIDs(float x, float y, int tolerance, int numberOfResults) {
        ...
    }

这里的 x、y 就是 screenPoint 的 x、y,tolerance 是识别所允许的容差,numberOfResults 是想要获取的结果数量,容差越大点击某点时可能获取的 Graphic 数量越多。

获取 GraphicId 具体的可以像下面这样操作:

    /**
     * 返回展示在屏幕点击位置的图形
     *
     * @param graphicsLayer 用来获取graphics ids 的 GraphicsLayer
     * @param x             点的x坐标
     * @param y             点的y坐标
     * @return 在 x y 位置上的 graphic
     */
    public int getTouchedGraphicId(GraphicsLayer graphicsLayer, float x, float y) {
        try {
            if (graphicsLayer == null) {
                Log.e(TAG, "getTouchedGraphicId: 请确认已加载图形层。");
                return -1;
            }
            // 获取 Point 附近的 graphics。
            int[] ids = graphicsLayer.getGraphicIDs(x, y, 10, 1);
            if (ids == null || ids.length == 0) {
                return -1;
            }
            return ids[0];
        } ca
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值