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组件

、效果图如下
ArcGIS Runtime SDK For Android 10.2.x版本之地图弹框Callout_第1张图片
三、代码示例
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> getCallOutData(Feature feature) {
    List> 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 map = new HashMap<>();
        map.put("key", entry.getKey().toString());
        map.put("value", entry.getValue().toString());
        list.add(map);
    }

    return list;
}
2、Callout的style样式如下

    
        titleTextColor="#000000"      
        titleTextSize = 10;          
        titleTextStyle = 0;          
        titleTextTypeFace = 0;        
        backgroundColor="#ffffff"    
        backgroundAlpha="230"        
        frameColor="#E8E8E6"        
        flat="true"                  
        cornerCurve="0"             
        anchor="8"                  
                   

3、Callout的布局文件如下
列表布局如下:


    
列表里的项目子布局如下:


    
    


你可能感兴趣的:(ArcGIS,for,Android)