ArcGIS Runtime SDK For Android 10.2.x版本之地图弹框Callout

一、介绍
主要调用的是com.esri.android.map.Callout类。具体使用方式大体如下:
1、获取到MapView的Callout组件,一个MapView只有一个Callout(可参看源码)
2、定义Callout的样式,通过setStyle方法
3、设置Callout的界面布局
4、在指定点位显示Callout组件

、效果图如下

三、代码示例
1、java代码如下
/**
* 初始化地图点击查询弹框
* @param feature 查询到的要素
* @param identifyPoint Callout显示的位置
*/
private final void initMapViewCallout(Feature feature, Point identifyPoint) {
    try {

        Callout callout = mMapView.getCallout();
        callout.setStyle(R.xml.calloutstyle);
        callout.setContent(createCallOutContent(feature));

        if (mMapView.getCallout().isShowing()) {
            mMapView.getCallout().hide();
        }

        //控制弹框位置
        if (feature.getGeometry().getType() == Geometry.Type.POINT) {
            Point point = (Point) feature.getGeometry();
            mMapView.getCallout().show(point);
        } else if (feature.getGeometry().getType() == Geometry.Type.POLYLINE) {
            Point point = GeometryEngine.getNearestCoordinate(feature.getGeometry(), identifyPoint, false).getCoordinate();
            mMapView.getCallout().show(point);
        } else if (feature.getGeometry().getType() == Geometry.Type.POLYGON) {
            if (GeometryEngine.contains(feature.getGeometry(), identifyPoint, mMapView.getSpatialReference())) {
                mMapView.getCallout().show(identifyPoint);
            } else {
                Point point = GeometryEngine.getNearestCoordinate(feature.getGeometry(), identifyPoint, false).getCoordinate();
                mMapView.getCallout().show(point);
            }
        }
    } catch (Exception e) {
        mMapView.getCallout().animatedHide();
        e.printStackTrace();
    }
}

private View createCallOutContent(Feature feature) {
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    View calloutView = layoutInflater.inflate(R.layout.callout, null);
    ListView listView = (ListView) calloutView.findViewById(R.id.callout_listview);

    SimpleAdapter adapter = new SimpleAdapter(this, getCallOutData(feature), R.layout.callout_item,
            new String[]{"key", "value"},
            new int[]{R.id.key, R.id.value});
    listView.setAdapter(adapter);

    return calloutView;
}

private List<Map<String, Object>> getCallOutData(Feature feature) {
    List<Map<String, Object>> list = new ArrayList<>();

    Set set = feature.getAttributes().entrySet();
    Iterator it = set.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        if (entry.getKey().toString().indexOf("Shape") != -1 || entry.getKey().toString().indexOf("OBJECTID") != -1)
            continue;
        Map<String, Object> map = new HashMap<>();
        map.put("key", entry.getKey().toString());
        map.put("value", entry.getValue().toString());
        list.add(map);
    }

    return list;
}
2、Callout的style样式如下
<?xml version="1.0" encoding="utf-8"?><resources>
    <calloutViewStyle>
        titleTextColor="#000000"      <!-- 标题颜色 -->
        titleTextSize = 10;          <!-- 标题文字大小 -->
        titleTextStyle = 0;          <!-- 字体样式 -->
        titleTextTypeFace = 0;        <!-- 字体类型设置 -->
        backgroundColor="#ffffff"    <!-- Callout背景颜色 -->
        backgroundAlpha="230"        <!-- Callout透明度 -->
        frameColor="#E8E8E6"        <!-- 边框颜色 -->
        flat="true"                  <!-- true表示2D图形,false表示3D图形 -->
        cornerCurve="0"             <!-- 边框的角的圆润程度 -->
        anchor="8"                  <!-- 锚点的位置-->
    </calloutViewStyle>               
</resources>

3、Callout的布局文件如下
列表布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="260dp"
    android:layout_height="130dp">
    <ListView
        android:id="@+id/callout_listview"
        android:layout_width="260dp"
        android:layout_height="130dp"></ListView>
</LinearLayout>
列表里的项目子布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="260dp"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/key"
        android:layout_width="130dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:textSize="22sp" />
    <TextView android:id="@+id/value"
        android:layout_width="130dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:textSize="18sp" />
</LinearLayout>


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值