目录

Interface (MapPolyline)

导入模块

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

MapPolyline

折线,继承BaseOverlay。在调用map.MapComponentController类的addPolyline方法时会返回该类型的实例。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

示例:

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

// 数组存放图片内容
let customTextures: Array<ResourceStr | image.PixelMap> = new Array();
// 图标存放在resources/rawfile目录下
customTextures.push('icon/img.png');
customTextures.push('icon/img_1.png');
let cusIndexNumber: Array<number> = new Array();
// cusIndexNumber数组长度与折线点数量必须相同,数组元素内容与customTextures下标相对应,图片从数组第二个元素开始选择
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

获取折线的颜色值。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
number ARGB格式颜色值。

示例:

let color: number = mapPolyline.getColor();

[h2]getColors

getColors(): Array<number>

获取折线的分段颜色值数组。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
Array<number> 折线的分段颜色值数组。

示例:

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

[h2]getEndCap

getEndCap(): mapCommon.CapStyle

获取折线的末尾端点样式。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
mapCommon.CapStyle 折线的末尾端点样式。

示例:

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

[h2]getJointType

getJointType(): mapCommon.JointType

获取折线除起始和结束顶点之外的所有顶点的节点类型属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
mapCommon.JointType 折线除起始和结束顶点之外的所有顶点的节点类型属性。

示例:

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

[h2]getPatterns

getPatterns(): Array<mapCommon.PatternItem>

获取折线的样式属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
Array<mapCommon.PatternItem> 折线的样式属性。

示例:

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

[h2]getPoints

getPoints(): Array<mapCommon.LatLng>

获取折线的顶点坐标属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
Array<mapCommon.LatLng> 折线的顶点坐标属性。

示例:

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

[h2]getStartCap

getStartCap(): mapCommon.CapStyle

获取折线的起始端点样式。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
mapCommon.CapStyle 折线的起始端点样式。

示例:

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

[h2]getWidth

getWidth(): number

获取折线的宽度属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
number 折线的宽度属性,单位:px。

示例:

let width: number = mapPolyline.getWidth();

[h2]isClickable

isClickable(): boolean

获取折线的可点击属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
boolean

折线的可点击性。

- true:可点击

- false:不可点击

示例:

let isClickable: boolean = mapPolyline.isClickable();

[h2]isGeodesic

isGeodesic(): boolean

获取折线的大地线属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
boolean

折线的大地线属性。

- true:大地线

- false:非大地线

示例:

let isGeodesic: boolean = mapPolyline.isGeodesic();

[h2]isGradient

isGradient(): boolean

获取折线的渐变属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

返回值:

类型 说明
boolean

折线的渐变属性。

- true:渐变

- false:不渐变

示例:

let isGradient: boolean = mapPolyline.isGradient();

[h2]setClickable

setClickable(clickable: boolean): void

设置折线是否可以点击。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
clickable boolean 是

设置折线是否可以点击,异常值不处理。

- true:可以

- false:不可以

示例:

mapPolyline.setClickable(true);

[h2]setColor

setColor(color: number): void

设置折线的颜色值。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
color number 是 ARGB格式颜色值,异常值不处理。

示例:

mapPolyline.setColor(0xff000000);

[h2]setColors

setColors(colors: Array<number>): void

设置折线的多段颜色值数组。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
colors Array<number> 是 多段颜色,ARGB格式颜色值数组,异常值不处理。

示例:

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

[h2]setEndCap

setEndCap(endCap: mapCommon.CapStyle): void

设置折线的末尾端点样式。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
endCap mapCommon.CapStyle 是 折线的末尾端点样式,异常值不处理。

示例:

mapPolyline.setEndCap(mapCommon.CapStyle.BUTT);

[h2]setGeodesic

setGeodesic(geodesic: boolean): void

设置是否将折线的每个线段绘制为大地线。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
geodesic boolean 是

将折线的每个线段绘制为大地线,异常值不处理。

- true:每段绘制为大地线

- false:不是大地线

示例:

mapPolyline.setGeodesic(true);

[h2]setGradient

setGradient(gradient: boolean): void

设置折线的渐变属性是否启用。需设置折线颜色方可生效。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
gradient boolean 是

设置折线的渐变属性是否启用,异常值不处理。

- true:渐变

- false:不渐变

示例:

mapPolyline.setGradient(true);

[h2]setJointType

setJointType(jointType: mapCommon.JointType): void

设置折线除起始和结束顶点之外的所有顶点的节点类型。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
jointType mapCommon.JointType 是 节点类型,异常值不处理。

示例:

mapPolyline.setJointType(mapCommon.JointType.DEFAULT);

[h2]setPatterns

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

设置折线的样式。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
patterns Array<mapCommon.PatternItem> 是 PatternItem对象的集合,异常值不处理。

示例:

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

设置折线的顶点坐标。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
points Array<mapCommon.LatLng> 是 折线顶点的集合。默认情况下,折线不闭合;要形成闭合的折线,起点和终点必须相同,异常值不处理。

示例:

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

设置折线的起始端点样式。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
startCap mapCommon.CapStyle 是 折线的起始端点样式,异常值不处理。

示例:

mapPolyline.setStartCap(mapCommon.CapStyle.BUTT);

[h2]setWidth

setWidth(width: number): void

设置折线的宽度。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

参数名 类型 必填 说明
width number 是 折线的宽度,单位:px,取值范围:大于等于0,异常值不处理。

示例:

mapPolyline.setWidth(20);

[h2]setCustomTexture

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

设置折线纹理。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 5.0.0(12)

参数:

参数名 类型 必填 说明
customTexture ResourceStr | image.PixelMap 是 折线纹理。建议纹理使用没有背景色(透明色)的图片,异常值不处理。

返回值:

类型 说明
Promise<void> Promise对象。无返回结果的Promise对象。

示例:

// 图标存放在resources/rawfile目录下
await mapPolyline.setCustomTexture("icon/naviline_arrow.png");

[h2]setCustomTexture

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

设置折线纹理。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.3(15)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 5.0.3(15)

参数:

参数名 类型 必填 说明
customTexture ResourceStr | image.PixelMap 是 折线纹理。建议纹理使用没有背景色(透明色)的图片,异常值不处理。
isTextureMappingUsed boolean 是

是否使用贴图模式进行纹理绘制,异常值不处理。

- true:使用贴图模式

- false:不使用贴图模式,建议纹理没有背景色(使用透明色)

返回值:

类型 说明
Promise<void> Promise对象。无返回结果的Promise对象。

示例:

// 图标需存放在resources/rawfile目录下
await mapPolyline.setCustomTexture("icon/naviline_arrow.png", true);

[h2]setCustomTextureIndexes

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

动态设置自定义纹理索引。折线设置纹理后,该接口可以将已有的纹理资源动态应用在各个折线段上。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.3(15)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 5.0.3(15)

参数:

参数名 类型 必填 说明
customTextureIndexes number[] 是 每个坐标对应的纹理索引。数组长度需要和points的数量保持一致,数组中的元素取值范围:自然数,异常值不处理。

返回值:

类型 说明
Promise<void> Promise对象。无返回结果的Promise对象。

示例:

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

[h2]addLineText

addLineText(lineText: mapCommon.LineText): void

添加折线的线条文本。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从API版本26.0.0开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 26.0.0

参数:

参数名 类型 必填 说明
lineText mapCommon.LineText 是 折线的线条文本参数,异常值作为无响应处理。

示例:

let textLine: mapCommon.LineText = {
  lineNames: ['第一段文字', '第二段文字'],
  lineNameIndexes: [0, 1, 1, 2],
  nameOnRight: false,
  color: 0xFF000000,
  fontSize: 15,
  strokeColor: 0xFFFFFFFF,
  fontStyle: 0
};
mapPolyline.addLineText(textLine);

[h2]removeLineText

removeLineText(): void

删除折线的文本。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从API版本26.0.0开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 26.0.0

示例:

mapPolyline.removeLineText();