The shared bicycle track interface such as: Xiaohuangche and Mobike interface layout adopts the AutoNavi map, and each track segment has a corresponding map texture
. First , we need to develop the map line segment texture in the AutoNavi map development environment. A few prerequisites are clarified:
- The line segment adds texture according to the official document is set in the PolylienOptions class
- The package where the PolylienOptions class is located is: com.amap.api.maps.model.PolylineOptions;
- There is also a PolylienOptions class in AMap corresponding to com.amap.api.maps2d.AMap, but this class cannot set textures
The official documentation states the following:
name | illustrate |
---|---|
setCustomTexture(BitmapDescriptor customTexture) | Set the texture of the line segment. It is recommended that the length and width of the texture resource be the nth power of 2 |
setCustomTextureIndex(java.util.List customTextureIndexs) | Set the segmented texture index array |
setCustomTextureList(java.util.List customTextureList) | Set segmented texture list |
setDottedLine(boolean isDottedLine) | Set whether to draw a dotted line, the default is false, draw a solid line |
setUseTexture(boolean useTexture) | Whether to use texture maps |
useGradient(boolean useGradient) | Set whether to use gradient color |
visible(boolean isVisible) | Set the visibility of line segments |
width(float width) | Set the width of the line segment, in pixels |
zIndex(float zIndex) | Set the value of the Z axis of the line segment |
First, you need your own texture map. The following three texture images
Code development:
place the texture image under the Asset file directory. The
tool class code is as follows:
/**
* Created by adminZPH on 2017/4/14.
* 设置线条中的纹理的方法
* @return PolylineOptions
* */
public static PolylineOptions GetPolylineOptions(){
//添加纹理图片
List<BitmapDescriptor> textureList = new ArrayList<BitmapDescriptor>();
BitmapDescriptor mRedTexture = BitmapDescriptorFactory
.fromAsset("icon_road_red_arrow.png");
BitmapDescriptor mBlueTexture = BitmapDescriptorFactory
.fromAsset("icon_road_blue_arrow.png");
BitmapDescriptor mGreenTexture = BitmapDescriptorFactory
.fromAsset("icon_road_green_arrow.png");
textureList.add(mRedTexture);
textureList.add(mBlueTexture);
textureList.add(mGreenTexture);
// 添加纹理图片对应的顺序
List<Integer> textureIndexs = new ArrayList<Integer>();
textureIndexs.add(0);
textureIndexs.add(1);
textureIndexs.add(2);
PolylineOptions polylienOptions=new PolylineOptions();
polylienOptions.setCustomTextureList(textureList);
polylienOptions.setCustomTextureIndex(textureIndexs);
polylienOptions.setUseTexture(true);
polylienOptions.width(7.0f);
return polylienOptions;
}
The above method is used to return a polylienOptions. If you have N latitude and longitude points, you need to add texture display on the map in pairs, you can use it directly. For
example :
for (int i =0; i < a.size() - 1; ++i) {
amap.addPolyline(GetPolylineOptions()).add(
new LatLng(a.get(i).getLatLonPoint().getLatitude(), a.get(i).getLatLonPoint().getLongitude()),
new LatLng(a.get(i + 1).getLatLonPoint().getLatitude(), a.get(i + 1).getLatLonPoint().getLongitude())
);
}
This can be achieved through the above, and the specific business logic is specifically written.
This sea2017.04.14 13:06