目录

Interface (ImageOverlay)

Modules to Import

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

ImageOverlay

Image overlay, which inherits from BaseOverlay. An instance of this type will be returned when the addImageOverlay 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 5.0.0(12).

System capability: SystemCapability.Map.Core

Since: 5.0.0(12)

Example:

let imageOverlayParams: mapCommon.ImageOverlayParams = {
  bounds: {
    southwest: { latitude: 32, longitude: 118 },
    northeast: { latitude: 32.4, longitude: 118.4 }
  },
  // The icon must be stored in the resources/rawfile directory.
  image: 'icon.png',
  transparency: 0.3,
  zIndex: 101,
  anchorU: 0.5,
  anchorV: 0.5,
  clickable: true,
  visible: true,
  bearing: 0
};
// Add an ImageOverlay.
let imageOverlay = await this.mapController.addImageOverlay(imageOverlayParams);
// Set the rotation angle of the ImageOverlay to 180 degrees.
imageOverlay.setBearing(180);
let bearing: number = imageOverlay.getBearing();

[h2]getBearing

getBearing(): number

Obtains the rotation angle of an ImageOverlay.

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)

Returns:

Type Description
number Rotation angle of an ImageOverlay, in degrees (°).

Example:

let bearing: number = imageOverlay.getBearing();

[h2]getBounds

getBounds(): mapCommon.LatLngBounds

Obtains the bounds of an ImageOverlay.

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)

Returns:

Type Description
mapCommon.LatLngBounds Bounds of an ImageOverlay.

Example:

let bounds: mapCommon.LatLngBounds = imageOverlay.getBounds();

[h2]getHeight

getHeight(): number

Obtains the height of an ImageOverlay.

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)

Returns:

Type Description
number Height of an ImageOverlay, in meters.

Example:

let height: number = imageOverlay.getHeight();

[h2]getWidth

getWidth(): number

Obtains the width of an ImageOverlay.

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)

Returns:

Type Description
number Width of an ImageOverlay, in meters.

Example:

let width: number = imageOverlay.getWidth();

[h2]getPosition

getPosition(): mapCommon.LatLng

Obtains the position of an ImageOverlay.

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)

Returns:

Type Description
mapCommon.LatLng Position of an ImageOverlay.

Example:

let position: mapCommon.LatLng = imageOverlay.getPosition();

[h2]getTransparency

getTransparency(): number

Obtains the transparency of an ImageOverlay.

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)

Returns:

Type Description
number Transparency of an ImageOverlay. The value range is [0, 1], where 0 indicates completely opaque and 1 indicates completely transparent.

Example:

let transparency: number = imageOverlay.getTransparency();

[h2]isClickable

isClickable(): boolean

Checks whether an ImageOverlay 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 5.0.0(12).

System capability: SystemCapability.Map.Core

Since: 5.0.0(12)

Returns:

Type Description
boolean

Indicates whether an ImageOverlay is tappable.

- true: yes

- false: no

Example:

let click: boolean = imageOverlay.isClickable();

[h2]setBearing

setBearing(bearing: number): void

Sets the rotation angle of an ImageOverlay.

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
bearing number Yes

Rotation angle of an ImageOverlay, in degrees (°).

0° is due north, and angles increase clockwise. The value range is [0, 360). The default value is 0. Values that fall outside the valid range will be adjusted to values within the range. For instance, 361° will be converted to 1°, and -1° will be converted to 359°.

Example:

imageOverlay.setBearing(180);

[h2]setClickable

setClickable(clickable: boolean): void

Sets whether an ImageOverlay 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 5.0.0(12).

System capability: SystemCapability.Map.Core

Since: 5.0.0(12)

Parameters:

Name Type Mandatory Description
clickable boolean Yes

Indicates whether an ImageOverlay is tappable.

- true: yes

- false: no

Example:

imageOverlay.setClickable(false);

[h2]setDimensions

setDimensions(width: number, height?: number): void

Sets the width and height of an ImageOverlay.

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
width number Yes Width, in meters. The value must be a positive integer. Invalid values are not processed.
height number No Height, in meters. The value must be a positive integer. Invalid values are not processed. If the height is not specified, it will be automatically calculated based on the ImageOverlay image's default aspect ratio.

Example:

imageOverlay.setDimensions(100000, 100000);

[h2]setImage

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

Sets the image of an ImageOverlay. This API uses a promise to return the result asynchronously.

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
image ResourceStr | image.PixelMap Yes

Image of an ImageOverlay.

Images in JPG, JPEG, PNG, GIF (only the first frame will be displayed), WEBP, and SVG formats are supported.

Note:

ResourceStr indicates either Resource type or string type. Input parameters of the string type can be in either of the following formats:

- Relative resource path: The image is stored in resources/rawfile. Set image to the relative path of the image file in the rawfile folder.

- toDataURL format: For example, set image to image/png;base64,<Base64-encoded byte value of the icon file>.

Returns:

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

Example:

// The icon must be stored in the resources/rawfile directory.
await imageOverlay.setImage("icon.png");

[h2]setBounds

setBounds(bounds: mapCommon.LatLngBounds): void

Sets the bounds of an ImageOverlay.

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
bounds mapCommon.LatLngBounds Yes Bounds of an ImageOverlay.

Example:

let bounds: mapCommon.LatLngBounds = {
  southwest: { longitude: 118, latitude: 31 },
  northeast: { longitude: 119, latitude: 32 }
};
imageOverlay.setBounds(bounds);

[h2]setPosition

setPosition(position: mapCommon.LatLng): void

Sets the position of an ImageOverlay.

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
position mapCommon.LatLng Yes Position of an ImageOverlay.

Example:

let position: mapCommon.LatLng = { longitude: 118, latitude: 31 };
imageOverlay.setPosition(position);

[h2]setTransparency

setTransparency(transparency: number): void

Sets the transparency of an ImageOverlay.

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
transparency number Yes Transparency of an ImageOverlay. The value range is [0, 1], where 0 indicates completely opaque and 1 indicates completely transparent. Invalid values are not processed.

Example:

imageOverlay.setTransparency(0.1);