目录

Interface (TileOverlay)

Modules to Import

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

TileOverlay

TileOverlay. This API inherits from BaseOverlay. TileOverlay is a map overlay implemented based on BaseOverlay and is used to display custom tiles. An instance of this type will be returned when the addTileOverlay method in the map.MapComponentController class is called.

For performance considerations, it is recommended that a maximum of 10 TileOverlays be added, and the resolution of the provided tiles be 256 × 256.

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)

Example:

let params: mapCommon.TileOverlayParams = {
  // URL of the TileOverlay, which must start with http or https and contain placeholders in the ?x={x}&y={y}&z={z} format.
  tileUrl: "https://xxx/xxx?x={x}&y={y}&z={z}",
  transparency: 0,
  fadeIn: false
};
let tileOverlay: map.TileOverlay = this.mapController?.addTileOverlay(params);

[h2]clearTileCache

clearTileCache(): void

Clears the cache of a TileOverlay.

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)

Example:

tileOverlay.clearTileCache();

[h2]setFadeIn

setFadeIn(fadeIn: boolean): void

Sets whether to enable TileOverlay fade-in.

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

Indicates whether to enable TileOverlay fade-in.

- true: yes

- false: no

Example:

tileOverlay.setFadeIn(false);

[h2]setTransparency

setTransparency(transparency: number): void

Sets the transparency of a TileOverlay.

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

Example:

tileOverlay.setTransparency(0.5);

[h2]getFadeIn

getFadeIn(): boolean

Checks whether TileOverlay fade-in is enabled.

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)

Returns:

Type Description
boolean

Indicates whether TileOverlay fade-in is enabled.

- true: yes

- false: no

Example:

let isFadeIn: boolean = tileOverlay.getFadeIn();

[h2]getTransparency

getTransparency(): number

Obtains the transparency of a TileOverlay.

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)

Returns:

Type Description
number Transparency of a TileOverlay. The value range is [0, 1]. The value 0 indicates opaque, and the value 1 indicates fully transparent.

Example:

let transparency: number = tileOverlay.getTransparency();

[h2]clearDiskCache

clearDiskCache(): Promise<void>

Clears the disk cache, which will also clear the memory cache. 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 6.0.0(20).

System capability: SystemCapability.Map.Core

Since: 6.0.0(20)

Returns:

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

Example:

tileOverlay.clearDiskCache();