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

xiaoxiao2021-02-28  105

一、介绍 主要调用的是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>
转载请注明原文地址: https://www.6miu.com/read-33143.html

最新回复(0)