ArcGIS for Android 10.2.9(3):Callout气泡的用法

Callout气泡的使用

首先我们要获取MapView中的气泡,通过MapView的getCallout()方法获取一个气泡。

Callout会实现的功能就是当你单击地图上一个标注的时候,会弹出一个衔套在MapView之上的弹窗,里面可以显示该标注的一些信息和属性。

Callout的API

效果图:
这里写图片描述

代码:

public class CalloutActivity extends AppCompatActivity {

    private MapView mMapView;

    private String mapServerUrl = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";

    private Callout mCallout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_callout);

        mMapView = (MapView) findViewById(R.id.mapview);

        ArcGISTiledMapServiceLayer arcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(mapServerUrl);
        mMapView.addLayer(arcGISTiledMapServiceLayer);

        mMapView.setOnSingleTapListener(new OnSingleTapListener() {
            @Override
            public void onSingleTap(float v, float v1) {
                Point point = mMapView.toMapPoint(v, v1);

                initCallout(point);
            }
        });
    }

    private void initCallout(Point point) {
        //获取一个气泡
        mCallout = mMapView.getCallout();

        //设置最大的长宽
        mCallout.setMaxWidth(500);
        mCallout.setMaxHeight(500);

        View callView = View.inflate(this, R.layout.callout, null);

        CalloutStyle calloutStyle = new CalloutStyle();
        //设置尖尖角的位置
        calloutStyle.setAnchor(Callout.ANCHOR_POSITION_LOWER_MIDDLE);
        mCallout.setStyle(calloutStyle);

        //也通过xml方式设置Callout的Style,新建一个xml放在res/xml下
        //mCallout.setStyle(R.xml.calloutstyle);

        mCallout.setOffset(0, -15);
        mCallout.show(point,callView);
    }


    protected void onResume() {
        super.onResume();
        mMapView.unpause();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.pause();
    }
也可以通过xml方式设置Callout的Style,新建一个xml放在res/xml下
 <?xml version="1.0" encoding="utf-8"?>
  <resources>
      <calloutViewStyle
          anchor="5"
          backgroundAlpha="255"
          backgroundColor="#ffffff"
          cornerCurveDp="20"
          frameColor="#000000"
          maxHeightDp="300"
          maxWidthDp="500" />
  </resources>

只需调用callout.setStyle方法来设置:

mCallout.setStyle(R.xml.calloutstyle);

或者在布局文件中设置:

 <com.esri.android.map.MapView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/mapview" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     calloutStyle="@xml/style3" />
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值