目录
2.1.1 transparency(float transparency)
2.1.2 image(BitmapDescriptor image)
2.1.3 extraInfo(Bundle extraInfo)
2.1.4 visible(boolean visible)
2.1.6 positionFromBounds(LatLngBounds bounds)
2.1.8 dimensions(int width,int height)
1. 简介
GroundOverlay是叠加覆盖物,属性设置对应GroundOverlayOptions类;
通过创建GroundOverlayOption对象options,添加属性到options,然后通过BaiduMap.addOverlay(options)返回一个GroundOverlay对象groundOverlay,如果需要更改大小、位置、透明度等等,就需要通过groundOverlay的函数来操作;
GroundOverlayOptions类设置属性来获取叠加覆盖物对象,GroundOverlay类用来动态设置叠加覆盖物对象;
2 常用函数
2.1 函数
2.1.1 transparency(float transparency)
设置覆盖物的透明度,范围:0.0~1.0,设置的值要注意范围;
2.1.2 image(BitmapDescriptor image)
设置覆盖物的图片信息
2.1.3 extraInfo(Bundle extraInfo)
设置覆盖物的额外信息
GroundOverlayOptions options = new GroundOverlayOptions();
//额外信息
Bundle bundle = new Bundle();
bundle.putString("redInfo","这个是测试使用的!");
options.extraInfo(bundle);
2.1.4 visible(boolean visible)
设置覆盖物是否显示
2.1.5 zIndex(int zIndex)
设置覆盖物的层次,zIndex值越大越在上层;
bludGroundOverlay.setZIndex(2);
redGroundOverlay.setZIndex(1);
这样bludGroundOverlay覆盖物将在redGroundOverlay层上面显示;
2.1.6 positionFromBounds(LatLngBounds bounds)
通过西南与东北范围来确定覆盖层的位置,就是两个坐标的经纬度互相组成4个点,然后确定一个矩形;
LatLng southwest = new LatLng(39.92235, 116.380338);
LatLng northeast = new LatLng(39.947246, 116.414977);
LatLngBounds bounds = new LatLngBounds.Builder().include(southwest).include(northeast).build();
GroundOverlayOptions options = new GroundOverlayOptions();
//ground位置信息,通过西南与东北坐标范围
options.positionFromBounds(bounds);
这个通过(39.92235, 116.380338)和(39.947246, 116.414977)两个坐标的经纬度,形成4个坐标点(39.92235, 116.380338)、(39.92235, 116.414977)、(39.92235, 116.380338)和(39.92235, 116.414977)组成一个矩形区域;
2.1.7 dimensions(int width)
设置覆盖物的宽度,单位为米;高度按照图片宽高比例;
2.1.8 dimensions(int width,int height)
设置覆盖物的宽度和高度,单位为米;
2.1.8 position(LatLng latLng)
通过坐标来设置覆盖物的位置;
2.1.9 anchor(float x,float y)
使用setPosition()方式设置覆盖物的位置,设置ground覆盖物的锚点比例,默认为0.5f,水平和垂直方向都居中对齐;
2.2 set和get
2.1中的所有函数都有对应的set和get函数,2.1中都是GroundOverlayOptions类中函数,如果使用GroundOverlay对象设置属性就需要setxxx(),例如位置设置用SetPosition(LatLng latLng);
2.3 函数间关系
dimensions(int width)、 dimensions(int width,int height)、 anchor(float x,float y)这3个函数只有在通过position(LatLng latLng)来设置覆盖物位置时才起作用;