目录

Polyline

Class Info

public final class Polyline

Defines a polyline, which is a list of vertices, where line segments are drawn between consecutive vertices. An instance of this type will be returned when the addPolyline method in the HuaweiMap class is called.

Public Method Summary

Qualifier and Type

Method Name and Description

void

remove()

Removes a polyline from a map.

void

setClickable(boolean clickable)

Sets whether a polyline is tappable.

void

setColor(int color)

Sets the stroke color of a polyline.

void

setColorValues(List<Integer> colors)

Sets colors for different segments of a polyline.

void

setEndCap(Cap endCap)

Sets the end vertex cap of a polyline.

void

setGeodesic(boolean geodesic)

Sets whether to draw each segment of a polyline as a geodesic.

void

setGradient(boolean on)

Sets whether a polyline is gradient.

void

setJointType(int jointType)

Sets the joint type of all vertices of a polyline, except the start and end vertices. For details about the allowed joint types, please refer to JointType.

void

setPattern(List<PatternItem> pattern)

Sets the stroke pattern of a polyline.

void

setPoints(List<LatLng> points)

Sets the vertex coordinates of a polyline.

void

setStartCap(Cap startCap)

Sets the start vertex cap of a polyline.

void

setTag(Object tag)

Sets the tag attribute of a polyline.

void

setVisible(boolean visible)

Sets whether a polyline is visible.

void

setWidth(float width)

Sets the stroke width of a polyline.

void

setZIndex(float zIndex)

Sets the z-index of a polyline.

Public Methods

[h2]remove

Method

public void remove()

Removes a polyline from a map. After the polyline is removed, the operations of all its methods will be undefined.

[h2]setClickable

Method

public void setClickable(boolean clickable)

Sets whether a polyline is tappable.

Parameters

Name

Description

clickable

Indicates whether a polyline is tappable.

  • true: yes
  • false: no

The default value is false.

[h2]setColor

Method

public void setColor(int color)

Sets the stroke color of a polyline.

Parameters

Name

Description

color

Color in ARGB format. By default, the stroke color is black (0xff000000).

[h2]setColorValues

Method

public void setColorValues(List<Integer> colors)

Sets colors for different segments of a polyline.

Parameters

Name

Description

colors

Colors of different segments of a polyline, in ARGB format.

[h2]setEndCap

Method

public void setEndCap(Cap endCap)

Sets the end vertex cap of a polyline.

Parameters

Name

Description

endCap

End vertex cap. The default value is ButtCap.

[h2]setGeodesic

Method

public void setGeodesic(boolean geodesic)

Sets whether to draw each segment of a polyline as a geodesic. If this parameter is not set, the default value false will be returned.

Parameters

Name

Description

geodesic

Indicates whether to draw each segment of a polyline as a geodesic.

  • true: yes
  • false: no

[h2]setGradient

Method

public void setGradient(boolean on)

Sets whether a polyline is gradient.

Parameters

Name

Description

on

Indicates whether a polyline is gradient.

  • true: yes
  • false (default): no

[h2]setJointType

Method

public void setJointType(int jointType)

Sets the joint type of all vertices of a polyline, except the start and end vertices. For details about the allowed joint types, please refer to JointType. If the joint type is not set or not an allowed one, the default value DEFAULT will be used.

Parameters

Name

Description

jointType

Joint type. The default value is DEFAULT.

[h2]setPattern

Method

public void setPattern(List<PatternItem> pattern)

Sets the stroke pattern of a polyline.

Parameters

Name

Description

pattern

PatternItem object set. The default value is null, indicating that the stroke is in the solid pattern.

[h2]setPoints

Method

public void setPoints(List<LatLng> points)

Sets the vertex coordinates of a polyline. By default, a straight line is drawn between the end vertex of the polyline and the set vertex coordinate point.

Parameters

Name

Description

points

Vertex set of a polyline. By default, a polyline is not a closed area. To form a closed area, the start and end points of the polyline must be the same.

[h2]setStartCap

Method

public void setStartCap(Cap startCap)

Sets the start vertex cap of a polyline.

Parameters

Name

Description

startCap

Start vertex cap. The default value is ButtCap.

[h2]setTag

Method

public void setTag(Object tag)

Sets the tag attribute of a polyline. The tag attribute can be any object. If null is passed, the tag attribute will be cleared. If you no longer use the tag attribute, call setTag(null) to clear it to prevent memory leakage from occurring on the app.

Parameters

Name

Description

tag

Tag of a polyline.

[h2]setVisible

Method

public void setVisible(boolean visible)

Sets whether a polyline is visible. If the polyline is invisible, it will not be drawn but all other states will be preserved.

Parameters

Name

Description

visible

Indicates whether a polyline is visible. The default value is true.

[h2]setWidth

Method

public void setWidth(float width)

Sets the stroke width of a polyline.

Parameters

Name

Description

width

Stroke width of a polyline, in pixels. The value must be greater than or equal to 0. The default value is 10.

NOTE:

To ensure compatibility, it is recommended that the actual stroke width triples the passed parameter value.

Throws

Name

Description

IllegalArgumentException

If the passed stroke width is a negative number.

[h2]setZIndex

Method

public void setZIndex(float zIndex)

Sets the z-index of a polyline. The z-index indicates the overlapping order of a polyline. A polyline with a larger z-index overlaps that with a smaller z-index. Polylines with the same z-index overlap each other by the order in which they are added.

NOTE:

The following formula must be met: Number of circles and polygons x 2 + Number of polylines and ground overlays ≤ 1450. If the formula is not met, overlapping errors may occur.

Parameters

Name

Description

zIndex

Z-index, which indicates the overlapping order of a polyline. By default, the z-index is 0.