We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesApplication ServicesMap KitArkTS APImap (Map Display)Interface (MapPolygon)

Interface (MapPolygon)

Modules to Import

Collapse
Word wrap
Dark theme
Copy code
  1. import { map, mapCommon } from '@kit.MapKit';

MapPolygon

MapPolygon. This API inherits from BaseOverlay. A MapPolygon can be convex or concave. It can span the 180th meridian and have holes that are not filled in. An instance of this type will be returned when the addPolygon 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:

Collapse
Word wrap
Dark theme
Copy code
  1. let polygonOptions: mapCommon.MapPolygonOptions = {
  2. points: [
  3. { latitude: 31.9844102, longitude: 118.7662 },
  4. { latitude: 31.9844102, longitude: 123.7662 },
  5. { latitude: 36.9844102, longitude: 123.7662 },
  6. { latitude: 36.9844102, longitude: 118.7662 }
  7. ],
  8. fillColor: 0xffff4500
  9. };
  10. let mapPolygon = await this.mapController.addPolygon(polygonOptions);

getFillColor

getFillColor(): number

Obtains the fill color of a MapPolygon, in ARGB format.

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:

Expand
Type Description
number Color in ARGB format.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let fillColor: number = mapPolygon.getFillColor();

getHoles

getHoles(): Array<Array<mapCommon.LatLng>>

Obtains holes in a MapPolygon.

NOTE

MapPolygon holes: A MapPolygon may contain one or more interior holes, creating a "hollow" effect. These areas are left unfilled, allowing for more complex and diverse internal structures within the MapPolygon.

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:

Expand
Type Description
Array<Array<mapCommon.LatLng>> Array of holes in a MapPolygon, which is a LatLng array.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let holes: Array<Array<mapCommon.LatLng>> = mapPolygon.getHoles();

getPoints

getPoints(): Array<mapCommon.LatLng>

Obtains vertex coordinates of a MapPolygon.

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:

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

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let points: Array<mapCommon.LatLng> = mapPolygon.getPoints();

getStrokeColor

getStrokeColor(): number

Obtains the stroke color of a MapPolygon's outline.

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:

Expand
Type Description
number Color in ARGB format.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let strokeColor: number = mapPolygon.getStrokeColor();

getJointType

getJointType(): mapCommon.JointType

Obtains the joint style of a MapPolygon.

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:

Expand
Type Description
mapCommon.JointType Joint style of a MapPolygon.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let jointType: mapCommon.JointType = mapPolygon.getJointType();

getPatterns

getPatterns(): Array<mapCommon.PatternItem>

Obtains the pattern of a MapPolygon's outline.

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:

Expand
Type Description
Array<mapCommon.PatternItem> Pattern of a MapPolygon's outline.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let patterns: Array<mapCommon.PatternItem> = mapPolygon.getPatterns();

getStrokeWidth

getStrokeWidth(): number

Obtains the stroke width of a MapPolygon's outline.

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:

Expand
Type Description
number Stroke width of a MapPolygon's outline, in pixels.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let strokeWidth: number = mapPolygon.getStrokeWidth();

isClickable

isClickable(): boolean

Checks whether a MapPolygon 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:

Expand
Type Description
boolean

Indicates whether a MapPolygon is tappable.

- true: yes

- false: no

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let clickable: boolean = mapPolygon.isClickable();

isGeodesic

isGeodesic(): boolean

Checks whether each segment of a MapPolygon is 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)

Returns:

Expand
Type Description
boolean

Indicates whether each segment of a MapPolygon is a geodesic.

- true: yes

- false: no

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let geodesic: boolean = mapPolygon.isGeodesic();

setClickable

setClickable(clickable: boolean): void

Sets whether a MapPolygon 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:

Expand
Name Type Mandatory Description
clickable boolean Yes

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

- true: yes

- false: no

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. mapPolygon.setClickable(true);

setFillColor

setFillColor(color: number): void

Sets the fill color of a MapPolygon.

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:

Expand
Name Type Mandatory Description
color number Yes Fill color of the MapPolygon, in ARGB format. Invalid values are not processed.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. mapPolygon.setFillColor(0xff000FFF);

setGeodesic

setGeodesic(geodesic: boolean): void

Sets whether to draw each segment of a MapPolygon 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:

Expand
Name Type Mandatory Description
geodesic boolean Yes

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

- true: yes

- false: no

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. mapPolygon.setGeodesic(true);

setHoles

setHoles(holes: Array<Array<mapCommon.LatLng>>): void

Sets holes in a MapPolygon.

NOTE

MapPolygon holes: A MapPolygon may contain one or more interior holes, creating a "hollow" effect. These areas are left unfilled, allowing for more complex and diverse internal structures within the MapPolygon.

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:

Expand
Name Type Mandatory Description
holes Array<Array<mapCommon.LatLng>> Yes Array of holes, which is a LatLng array. Invalid values are not processed.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let holes: Array<Array<mapCommon.LatLng>> = [
  2. [
  3. {
  4. latitude: 32.98,
  5. longitude: 121.76
  6. },
  7. {
  8. latitude: 32.98,
  9. longitude: 119.76
  10. },
  11. {
  12. latitude: 35.98,
  13. longitude: 119.76
  14. },
  15. {
  16. latitude: 35.98,
  17. longitude: 121.76
  18. }
  19. ]
  20. ];
  21. mapPolygon.setHoles(holes);
NOTE

When coordinates of a hole coincide with the outline of the MapPolygon, it can lead to rendering anomalies, such as extra hollow regions being displayed.

setPoints

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

Sets the vertex coordinates of a MapPolygon.

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:

Expand
Name Type Mandatory Description
points Array<mapCommon.LatLng> Yes Array of vertex coordinates of a MapPolygon. Invalid values are not processed.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let points: Array<mapCommon.LatLng> = [
  2. {
  3. latitude: 31.98,
  4. longitude: 115.76
  5. },
  6. {
  7. latitude: 31.98,
  8. longitude: 118.76
  9. },
  10. {
  11. latitude: 35.98,
  12. longitude: 118.76
  13. },
  14. {
  15. latitude: 35.98,
  16. longitude: 118.76
  17. }
  18. ];
  19. mapPolygon.setPoints(points);

setStrokeColor

setStrokeColor(color: number): void

Sets the stroke color of a MapPolygon's outline.

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:

Expand
Name Type Mandatory Description
color number Yes Stroke color of a MapPolygon's outline, in ARGB format. Invalid values are not processed.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. mapPolygon.setStrokeColor(0xff00DB93);

setJointType

setJointType(jointType: mapCommon.JointType): void

Sets the joint style of a MapPolygon.

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:

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

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. mapPolygon.setJointType(mapCommon.JointType.ROUND);

setPatterns

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

Sets the pattern of a MapPolygon's outline.

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:

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

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. let linePatterns: Array<mapCommon.PatternItem> = [
  2. {
  3. type: mapCommon.PatternItemType.DASH,
  4. length: 100
  5. },
  6. {
  7. type: mapCommon.PatternItemType.DOT,
  8. length: 100
  9. },
  10. {
  11. type: mapCommon.PatternItemType.GAP,
  12. length: 100
  13. }
  14. ];
  15. mapPolygon.setPatterns(linePatterns);

setStrokeWidth

setStrokeWidth(width: number): void

Sets the stroke width of a MapPolygon's outline.

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:

Expand
Name Type Mandatory Description
width number Yes Stroke width, in px. The value must be greater than or equal to 0. Invalid values are not processed.

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. mapPolygon.setStrokeWidth(30);
Search in References
Enter a keyword.