目录

Interface (BaseOverlay)

Modules to Import

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

BaseOverlay

Base class of overlays. Overlays such as Marker, MapPolyline, MapPolygon, MapCircle, MapArc, ImageOverlay, and BasePriorityOverlay inherit from this base class.

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)

Return Type Method
string

getId()

Obtains the ID of an overlay.

number

getZIndex()

Obtains the z-index of an overlay.

Object

getTag()

Obtains the tag of an overlay.

boolean

isVisible()

Visibility of an overlay.

void

remove()

Removes an overlay from a map.

void

setZIndex(zIndex: number)

Sets the z-index of an overlay.

void

setTag(tag: Object)

Sets the tag of an overlay.

void

setVisible(visible: boolean)

Sets whether an overlay is visible.

[h2]getId

getId(): string

Obtains the ID of an overlay.

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
string ID of an overlay.

Example:

// Use a Marker as an example.
let markerOptions: mapCommon.MarkerOptions = {
  position: {
    latitude: 39.9,
    longitude: 116.4
  }
};
let marker: map.Marker = await this.mapController.addMarker(markerOptions);
let id: string = marker.getId();

[h2]getZIndex

getZIndex(): number

Obtains the z-index of an overlay.

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 Z-index of an overlay. The z-index indicates the overlapping order of an overlay. An overlay with a larger z-index overlaps that with a smaller z-index. Overlays with the same z-index overlap each other by the order in which they are added.

Example:

// Use a Marker as an example.
let zIndex: number = marker.getZIndex();

[h2]getTag

getTag(): Object

Obtains the tag of an overlay.

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
Object Tag of an overlay.

Example:

// Use a Marker as an example.
let tag: Object = marker.getTag();

[h2]isVisible

isVisible(): boolean

Checks whether an overlay is visible.

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 an overlay is visible.

- true: yes

- false: no

Example:

// Use a Marker as an example.
let isVisible: boolean = marker.isVisible();

[h2]remove

remove(): void

Removes an overlay from a map.

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:

// Use a Marker as an example.
marker.remove();

[h2]setZIndex

setZIndex(zIndex: number): void

Sets the z-index of an overlay.

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
zIndex number Yes Z-index of an overlay. The z-index indicates the overlapping order of an overlay. An overlay with a larger z-index overlaps that with a smaller z-index. Overlays with the same z-index overlap each other by the order in which they are added. Invalid values are not processed.

Example:

// Use a Marker as an example.
marker.setZIndex(3);

[h2]setTag

setTag(tag: Object): void

Sets the tag of an overlay. The tag can be any object. If the tag is set to null, it will be cleared. When you no longer need a tag, call setTag(null) or setTag(undefined) to clear it to prevent memory leakage from occurring on the app.

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
tag Object Yes Overlay tag. Invalid values are not processed.

Example:

// Use a Marker as an example.
let tag = "tag-1";
marker.setTag(tag);

[h2]setVisible

setVisible(visible: boolean): void

Sets whether an overlay is visible. By default, an overlay is visible.

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
visible boolean Yes

Indicates whether an overlay is visible. Invalid values are not processed.

- true: yes

- false: no

Example:

// Use a Marker as an example.
marker.setVisible(true);