目录

Interface (MapPolyline)

Modules to Import

import { map, mapCommon } from '@kit.MapKit';

MapPolyline

MapPolyline, which inherits from BaseOverlay. An instance of this type will be returned when the addPolyline method in the map.MapComponentController class is called.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Example:

import { image } from '@kit.ImageKit';

// Store images in an array.
let customTextures: Array<ResourceStr | image.PixelMap> = new Array();
// The icons are stored in the resources/rawfile directory.
customTextures.push('icon/img.png');
customTextures.push('icon/img_1.png');
let cusIndexNumber: Array<number> = new Array();
// The length of the cusIndexNumber array must be the same as the number of MapPolyline points. The array element content corresponds to the subscripts of customTextures. Images are stored from the second element in the array.
cusIndexNumber.push(0, 0, 1);
let polylineOption: mapCommon.MapPolylineOptions = {
  points: [
    { latitude: 31.68, longitude: 118.166 },
    { latitude: 31.48, longitude: 118.366 },
    { latitude: 31.28, longitude: 118.766 }
  ],
  customTextures: customTextures,
  customTextureIndexes: cusIndexNumber
};
let mapPolyline = await this.mapController.addPolyline(polylineOption);

[h2]getColor

getColor(): number

Obtains the color of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
number Color in ARGB format.

Example:

let color: number = mapPolyline.getColor();

[h2]getColors

getColors(): Array<number>

Obtains colors of segments of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
Array<number> Array of colors of segments in a MapPolyline.

Example:

let colors: Array<number> = mapPolyline.getColors();

[h2]getEndCap

getEndCap(): mapCommon.CapStyle

Obtains the end cap style of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
mapCommon.CapStyle End cap style of a MapPolyline.

Example:

let endCap: mapCommon.CapStyle = mapPolyline.getEndCap();

[h2]getJointType

getJointType(): mapCommon.JointType

Obtains the joint type of all vertices of a MapPolyline, except the start and end vertices.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
mapCommon.JointType Joint type of all vertices of a MapPolyline, except the start and end vertices.

Example:

let jointType: mapCommon.JointType = mapPolyline.getJointType();

[h2]getPatterns

getPatterns(): Array<mapCommon.PatternItem>

Obtains the patterns of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
Array<mapCommon.PatternItem> Patterns of a MapPolyline.

Example:

let patterns: Array<mapCommon.PatternItem> = mapPolyline.getPatterns();

[h2]getPoints

getPoints(): Array<mapCommon.LatLng>

Obtains the vertex coordinates of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
Array<mapCommon.LatLng> Vertex coordinates of a MapPolyline.

Example:

let points: Array<mapCommon.LatLng> = mapPolyline.getPoints();

[h2]getStartCap

getStartCap(): mapCommon.CapStyle

Obtains the start cap style of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
mapCommon.CapStyle Start cap style of a MapPolyline.

Example:

let startCap: mapCommon.CapStyle = mapPolyline.getStartCap();

[h2]getWidth

getWidth(): number

Obtains the width of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
number Width of a MapPolyline, in pixels.

Example:

let width: number = mapPolyline.getWidth();

[h2]isClickable

isClickable(): boolean

Checks whether a MapPolyline is tappable.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
boolean

Indicates whether a MapPolyline is tappable.

- true: yes

- false: no

Example:

let isClickable: boolean = mapPolyline.isClickable();

[h2]isGeodesic

isGeodesic(): boolean

Checks whether segments of a MapPolyline are geodesics.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
boolean

Indicates whether segments of a MapPolyline are geodesics.

- true: yes

- false: no

Example:

let isGeodesic: boolean = mapPolyline.isGeodesic();

[h2]isGradient

isGradient(): boolean

Checks whether a MapPolyline is gradient.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
boolean

Indicates whether a MapPolyline is gradient.

- true: yes

- false: no

Example:

let isGradient: boolean = mapPolyline.isGradient();

[h2]setClickable

setClickable(clickable: boolean): void

Sets whether a MapPolyline is tappable.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
clickable boolean Yes

Indicates whether a MapPolyline is tappable. Invalid values are not processed.

- true: yes

- false: no

Example:

mapPolyline.setClickable(true);

[h2]setColor

setColor(color: number): void

Sets the color of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
color number Yes Color in ARGB format. Invalid values are not processed.

Example:

mapPolyline.setColor(0xff000000);

[h2]setColors

setColors(colors: Array<number>): void

Sets colors for segments of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
colors Array<number> Yes Array of segment colors in ARGB format. Invalid values are not processed.

Example:

mapPolyline.setColors([0xffffff00, 0xff000000]);

[h2]setEndCap

setEndCap(endCap: mapCommon.CapStyle): void

Sets the end cap style of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
endCap mapCommon.CapStyle Yes End cap style of a MapPolyline. Invalid values are not processed.

Example:

mapPolyline.setEndCap(mapCommon.CapStyle.BUTT);

[h2]setGeodesic

setGeodesic(geodesic: boolean): void

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

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
geodesic boolean Yes

Indicates whether to draw each segment of a MapPolyline as a geodesic. Invalid values are not processed.

- true: yes

- false: no

Example:

mapPolyline.setGeodesic(true);

[h2]setGradient

setGradient(gradient: boolean): void

Sets whether a MapPolyline is gradient. It takes effect only when the MapPolyline color is specified.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
gradient boolean Yes

Indicates whether to enable the gradient attribute of a MapPolyline. Invalid values are not processed.

- true: yes

- false: no

Example:

mapPolyline.setGradient(true);

[h2]setJointType

setJointType(jointType: mapCommon.JointType): void

Sets the joint type of all vertices of a MapPolyline, except the start and end vertices.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
jointType mapCommon.JointType Yes Joint type. Invalid values are not processed.

Example:

mapPolyline.setJointType(mapCommon.JointType.DEFAULT);

[h2]setPatterns

setPatterns(patterns: Array<mapCommon.PatternItem>): void

Sets patterns of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
patterns Array<mapCommon.PatternItem> Yes Array of PatternItem objects. Invalid values are not processed.

Example:

let linePattern: Array<mapCommon.PatternItem> = [
  { type: mapCommon.PatternItemType.DASH, length: 100 },
  { type: mapCommon.PatternItemType.DOT, length: 100 },
  { type: mapCommon.PatternItemType.GAP, length: 100 }
];
mapPolyline.setPatterns(linePattern);

[h2]setPoints

setPoints(points: Array<mapCommon.LatLng>): void

Sets the vertex coordinates of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
points Array<mapCommon.LatLng> Yes Array of vertices of a MapPolyline. A MapPolyline is open by default. To form a closed MapPolyline, its start and end vertices must coincide.

Example:

let points: Array<mapCommon.LatLng> = [
  { latitude: 31.18, longitude: 118.766 },
  { latitude: 31.38, longitude: 118.366 },
  { latitude: 31.68, longitude: 118.566 },
  { latitude: 31.98, longitude: 118.266 },
  { latitude: 31.88, longitude: 118.866 }
];
mapPolyline.setPoints(points);

[h2]setStartCap

setStartCap(startCap: mapCommon.CapStyle): void

Sets the start cap style of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
startCap mapCommon.CapStyle Yes Start cap style of a MapPolyline. Invalid values are not processed.

Example:

mapPolyline.setStartCap(mapCommon.CapStyle.BUTT);

[h2]setWidth

setWidth(width: number): void

Sets the width of a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
width number Yes Width of a MapPolyline, in pixels. The value must be greater than or equal to 0. Invalid values are not processed.

Example:

mapPolyline.setWidth(20);

[h2]setCustomTexture

setCustomTexture(customTexture: ResourceStr | image.PixelMap): Promise<void>

Sets the texture of a MapPolyline. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.Map.Core

Since: 5.0.0(12)

Parameters:

Name Type Mandatory Description
customTexture ResourceStr | image.PixelMap Yes Texture of a MapPolyline. You are advised to use an image with a transparent background as the texture. Invalid values are not processed.

Returns:

Type Description
Promise<void> Promise that returns no value.

Example:

// The icon is stored in the resources/rawfile directory.
await mapPolyline.setCustomTexture("icon/naviline_arrow.png");

[h2]setCustomTexture

setCustomTexture(customTexture: ResourceStr | image.PixelMap, isTextureMappingUsed: boolean): Promise<void>

Sets the texture of a MapPolyline. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 5.0.3(15).

System capability: SystemCapability.Map.Core

Since: 5.0.3(15)

Parameters:

Name Type Mandatory Description
customTexture ResourceStr | image.PixelMap Yes Texture of a MapPolyline. You are advised to use an image with a transparent background as the texture. Invalid values are not processed.
isTextureMappingUsed boolean Yes

Indicates whether to use texture mapping for texture drawing. Invalid values are not processed.

- true: yes

- false: no. It is recommended that the texture have no background color (using a transparent background).

Returns:

Type Description
Promise<void> Promise that returns no value.

Example:

// The icon must be stored in the resources/rawfile directory.
await mapPolyline.setCustomTexture("icon/naviline_arrow.png", true);

[h2]setCustomTextureIndexes

setCustomTextureIndexes(customTextureIndexes: number[]): Promise<void>

Dynamically sets custom texture indexes. After textures set, this API can dynamically apply the existing texture resources to each MapPolyline segment. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 5.0.3(15).

System capability: SystemCapability.Map.Core

Since: 5.0.3(15)

Parameters:

Name Type Mandatory Description
customTextureIndexes number[] Yes Texture indexes corresponding to each coordinate. The array length must be the same as the number of points. The elements in the array must be natural numbers. Invalid values are not processed.

Returns:

Type Description
Promise<void> Promise that returns no value.

Example:

await mapPolyline.setCustomTextureIndexes([0,1,0]);

[h2]addLineText

addLineText(lineText: mapCommon.LineText): void

Adds line text to a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Map.Core

Since: 26.0.0

Parameters:

Name Type Mandatory Description
lineText mapCommon.LineText Yes Line text parameter of a MapPolyline. If an invalid value is passed, this API will not respond.

Example:

let textLine: mapCommon.LineText = {
  lineNames: ['First text segment', 'Second text segment'],
  lineNameIndexes: [0, 1, 1, 2],
  nameOnRight: false,
  color: 0xFF000000,
  fontSize: 15,
  strokeColor: 0xFFFFFFFF,
  fontStyle: 0
};
mapPolyline.addLineText(textLine);

[h2]removeLineText

removeLineText(): void

Deletes text from a MapPolyline.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Map.Core

Since: 26.0.0

Example:

mapPolyline.removeLineText();