下面列出了怎么用com.google.android.gms.maps.model.Cap的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Convert the list of latitude and longitude to the polyline options.
*
* @param context A context.
* @param locationList A list of latitude and longitude.
* @param width Width of the polyline in screen pixels.
* @param color Color of the polyline as a 32-bit ARGB color.
* @param clickable Is polyline clickable.
* @param startCap Cap at the start vertex of the polyline.
* @param endCap Cap at the end vertex of the polyline.
* @return Options for a polyline.
* @since 1.2.0
*/
public static PolylineOptions createPolyline(
@NonNull Context context,
@Nullable ArrayList<LatLng> locationList,
@Dimension(unit = Dimension.DP) int width,
@ColorInt int color,
boolean clickable,
@Nullable Cap startCap,
@Nullable Cap endCap
) {
return createPolyline(
context,
locationList,
width,
color,
clickable,
JointType.DEFAULT,
startCap,
endCap,
null
);
}
/**
* Convert the list of latitude and longitude to the polyline options in transit mode.
*
* @param context A context.
* @param stepList A list of latitude and longitude for the steps.
* @param transitWidth Width of the polyline in screen pixels for transit polyline.
* @param transitColor Color of the polyline as a 32-bit ARGB color for transit polyline.
* @param walkingWidth Width of the polyline in screen pixels for walking polyline.
* @param walkingColor Color of the polyline as a 32-bit ARGB color for walking polyline.
* @param clickable Is polyline clickable.
* @param startCap Cap at the start vertex of the polyline.
* @param endCap Cap at the end vertex of the polyline.
* @return Options for a polyline.
* @since 1.2.0
*/
public static ArrayList<PolylineOptions> createTransitPolyline(
@NonNull Context context,
@Nullable List<Step> stepList,
@Dimension(unit = Dimension.DP) int transitWidth,
@ColorInt int transitColor,
@Dimension(unit = Dimension.DP) int walkingWidth,
@ColorInt int walkingColor,
boolean clickable,
@Nullable Cap startCap,
@Nullable Cap endCap) {
return createTransitPolyline(
context,
stepList,
transitWidth,
transitColor,
null,
walkingWidth,
walkingColor,
null,
clickable,
JointType.DEFAULT,
startCap,
endCap
);
}
/**
* Convert the list of latitude and longitude to the polyline options.
*
* @param context A context.
* @param locationList A list of latitude and longitude.
* @param width Width of the polyline in screen pixels.
* @param color Color of the polyline as a 32-bit ARGB color.
* @param clickable Is polyline clickable.
* @param jointType Joint type for all vertices of the polyline except the start and end vertices.
* @param startCap Cap at the start vertex of the polyline.
* @param endCap Cap at the end vertex of the polyline.
* @param patternItemList Stroke pattern for the polyline.
* @return Options for a polyline.
* @since 1.2.0
*/
public static PolylineOptions createPolyline(
@NonNull Context context,
@Nullable ArrayList<LatLng> locationList,
@Dimension(unit = Dimension.DP) int width,
@ColorInt int color,
boolean clickable,
int jointType,
@Nullable Cap startCap,
@Nullable Cap endCap,
@Nullable List<PatternItem> patternItemList) {
PolylineOptions rectLine = new PolylineOptions().width(dpToPx(context, width)).color(color).geodesic(true);
rectLine.clickable(clickable);
rectLine.jointType(jointType);
if (patternItemList != null) {
rectLine.pattern(patternItemList);
}
if (startCap != null) {
rectLine.startCap(startCap);
}
if (endCap != null) {
rectLine.endCap(endCap);
}
if (locationList != null && locationList.size() > 0) {
for (LatLng location : locationList) {
rectLine.add(location);
}
}
return rectLine;
}
private Cap getSelectedCap(int pos) {
switch (CAP_TYPE_NAME_RESOURCE_IDS[pos]) {
case R.string.cap_butt:
return new ButtCap();
case R.string.cap_square:
return new SquareCap();
case R.string.cap_round:
return new RoundCap();
case R.string.cap_image:
return new CustomCap(
BitmapDescriptorFactory.fromResource(R.drawable.chevron),
CUSTOM_CAP_IMAGE_REF_WIDTH_PX);
}
return null;
}
@Override
public Cap getEndCap() {
return polyline.getEndCap();
}
@Override
public Cap getStartCap() {
return polyline.getStartCap();
}
@Override
public void setEndCap(Cap endCap) {
polyline.setEndCap(endCap);
}
@Override
public void setStartCap(Cap startCap) {
polyline.setStartCap(startCap);
}
public CurveOptions endCap(Cap cap) {
real.endCap(cap);
return this;
}
public Cap getEndCap() {
return real.getEndCap();
}
public Cap getStartCap() {
return real.getStartCap();
}
public CurveOptions startCap(Cap cap) {
real.startCap(cap);
return this;
}
/**
* Convert the list of latitude and longitude to the polyline options in transit mode.
*
* @param context A context.
* @param stepList A list of latitude and longitude for the steps.
* @param transitWidth Width of the polyline in screen pixels for transit polyline.
* @param transitColor Color of the polyline as a 32-bit ARGB color for transit polyline.
* @param transitPatternItemList Stroke pattern for the polyline for transit polyline.
* @param walkingWidth Width of the polyline in screen pixels for walking polyline.
* @param walkingColor Color of the polyline as a 32-bit ARGB color for walking polyline.
* @param walkingPatternItemList Stroke pattern for the polyline for walking polyline.
* @param clickable Is polyline clickable.
* @param jointType Joint type for all vertices of the polyline except the start and end vertices.
* @param startCap Cap at the start vertex of the polyline.
* @param endCap Cap at the end vertex of the polyline.
* @return Options for a polyline.
* @since 1.2.0
*/
public static ArrayList<PolylineOptions> createTransitPolyline(
@NonNull Context context,
@Nullable List<Step> stepList,
@Dimension(unit = Dimension.DP) int transitWidth,
@ColorInt int transitColor,
@Nullable List<PatternItem> transitPatternItemList,
@Dimension(unit = Dimension.DP) int walkingWidth,
@ColorInt int walkingColor,
@Nullable List<PatternItem> walkingPatternItemList,
boolean clickable,
int jointType,
@Nullable Cap startCap,
@Nullable Cap endCap
) {
ArrayList<PolylineOptions> polylineOptionsList = new ArrayList<>();
if (stepList != null && stepList.size() > 0) {
for (Step step : stepList) {
ArrayList<LatLng> directionPointList = new ArrayList<>();
convertStepToPosition(step, directionPointList);
if (step.isContainStepList()) {
polylineOptionsList.add(createPolyline(
context,
directionPointList,
walkingWidth,
walkingColor,
clickable,
jointType,
startCap,
endCap,
walkingPatternItemList
));
} else {
polylineOptionsList.add(createPolyline(
context,
directionPointList,
transitWidth,
transitColor,
clickable,
jointType,
startCap,
endCap,
transitPatternItemList
));
}
}
}
return polylineOptionsList;
}
public Cap getStartCap() {
return startCap;
}
public PathOption setStartCap(Cap startCap) {
this.startCap = startCap;
return this;
}
public Cap getEndCap() {
return endCap;
}
public PathOption setEndCap(Cap endCap) {
this.endCap = endCap;
return this;
}
@Nullable
public Cap getStartCap() {
return startCap;
}
public TransitPathOption setStartCap(@Nullable Cap startCap) {
this.startCap = startCap;
return this;
}
@Nullable
public Cap getEndCap() {
return endCap;
}
public TransitPathOption setEndCap(@Nullable Cap endCap) {
this.endCap = endCap;
return this;
}
Cap getEndCap();
Cap getStartCap();
void setEndCap(Cap endCap);
void setStartCap(Cap startCap);