This module provides APIs for obtaining a static map.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
Start version: 4.1.0(11)
This module provides the method described in the following table to implement the function of obtaining a static map.
Name | Description |
|---|---|
getMapImage(options: StaticMapOptions) | Creates a static map based on the provided parameters. |
getMapImage(context: common.Context, options: StaticMapOptions) | Creates a static map based on the provided parameters. The context can be passed. |
This module provides the APIs described in the following table to implement the function of obtaining a static map.
Name | Type | Description |
|---|---|---|
StaticMapOptions | Defines static map parameters. | |
StaticMapMarker | Defines Marker positions. | |
StaticMapPath | Defines information of paths to be added to the static map. | |
IconSize | Defines the default icon size of a Marker on the static map. |
getMapImage(options: StaticMapOptions): Promise<image.PixelMap>
Creates a static map based on the provided parameters. This API returns the result asynchronously through a promise.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.Map.Core
Start version: 4.1.0(11)
Parameters:
Name | Type | Mandatory | Description |
|---|---|---|---|
options | Yes | Static map parameters. |
Returns:
Type | Description |
|---|---|
Promise<image.PixelMap> | image.PixelMap object returned through a promise. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
Error Code | Error Message |
|---|---|
401 | Invalid input parameter. |
1002600001 | System internal error. |
1002600002 | Failed to connect to the Map Kit server. |
1002600003 | App authentication failed. |
1002600004 | The Map permission is not enabled. |
1002600005 | The network is unavailable. |
1002600006 | The API call times exceed the quota. |
1002600007 | The API QPS exceeds the quota. |
1002600008 | The API is in arrears. |
1002600009 | The API has not subscribed to any pay-as-you-go package. |
1002600010 | The server is busy. Please wait and try again. |
Example:
let staticMapOptions: staticMap.StaticMapOptions = {
location: {
latitude: 39.9,
longitude: 116.4
},
zoom: 3,
imageWidth: 10,
imageHeight: 10
};
await staticMap.getMapImage(staticMapOptions); getMapImage(context: common.Context, options: StaticMapOptions): Promise<image.PixelMap>
Creates a static map based on the provided parameters. The context can be passed. This API returns the result asynchronously through a promise.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.Map.Core
Start version: 5.0.0(12)
Parameters:
Name | Type | Mandatory | Description |
|---|---|---|---|
context | Yes | Context. | |
options | Yes | Static map parameters. |
Returns:
Type | Description |
|---|---|
Promise<image.PixelMap> | image.PixelMap object returned through a promise. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
Error Code | Error Message |
|---|---|
401 | Invalid input parameter. |
1002600001 | System internal error. |
1002600002 | Failed to connect to the Map Kit server. |
1002600003 | App authentication failed. |
1002600004 | The Map permission is not enabled. |
1002600005 | The network is unavailable. |
1002600006 | The API call times exceed the quota. |
1002600007 | The API QPS exceeds the quota. |
1002600008 | The API is in arrears. |
1002600009 | The API has not subscribed to any pay-as-you-go package. |
1002600010 | The server is busy. Please wait and try again. |
Example:
let staticMapOptions: staticMap.StaticMapOptions = {
location: {
latitude: 39.9,
longitude: 116.4
},
zoom: 3,
imageWidth: 10,
imageHeight: 10
};
await staticMap.getMapImage(getContext(), staticMapOptions); Defines parameters for creating a static 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 API version 4.1.0(11).
System capability: SystemCapability.Map.Core
Start version: 4.1.0(11)
Parameters:
Name | Type | Read-only | Optional | Description |
|---|---|---|---|---|
location | No | No | Coordinates of the map center point. | |
zoom | number | No | No | Map zoom level, which must be an integer ranging from 2 to 17. If this parameter is set to a decimal, the decimal will be rounded down. |
imageWidth | number | No | No | Image width. If scale is set to 1, the value range of this parameter is (0, 1024]. If scale is set to 2, the value range of this parameter is (0, 512]. Unit: px |
imageHeight | number | No | No | Image height. If scale is set to 1, the value range of this parameter is (0, 1024]. If scale is set to 2, the value range of this parameter is (0, 512]. Unit: px |
scale | number | No | Yes | Map scale, which is 1 or 2. The default value is 1. This parameter can be used to obtain a map image with a high resolution. The actual size (in pixels) of the map image equals the product of scale, imageWidth, and imageHeight. |
logoAlignment | No | Yes | Map logo alignment mode. The default value is BOTTOM_START, indicating the lower left corner. | |
markers | Array<StaticMapMarker> | No | Yes | Adds Markers to the map image. NOTE: Loading icon resources affects network performance. It is advised to use no more than three Markers. |
path | No | Yes | Adds paths to the static map. | |
dayNightMode | No | Yes | Day/Dark mode. The default value is mapCommon.DayNightMode.DAY. Start version: 5.0.0(12) Atomic service API: This API can be used in atomic services since API version 5.0.0(12). |
Example:
let staticMapOptions: staticMap.StaticMapOptions = {
location: {
latitude: 39.9,
longitude: 116.4
},
zoom: 3,
imageWidth: 10,
imageHeight: 10
}; Defines the position of a Marker.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 4.1.0(11).
System capability: SystemCapability.Map.Core
Start version: 4.1.0(11)
Parameters:
Name | Type | Read-only | Optional | Description |
|---|---|---|---|---|
location | No | No | Marker coordinates. | |
icon | string | No | Yes | Custom icon of a Marker. The value must start with http:// or https://. If no icon is set or the icon does not meet the requirements, the default icon will be used. NOTE: The icon must be in PNG format, no larger than 16 KB in size, and with dimensions no greater than 128 x 128 pixels. |
defaultIconSize | No | Yes | Size of the default icon. The default value is IconSize.NORMAL, indicating a medium size. | |
font | string | No | Yes | Text of a Marker. |
fontColor | number | No | Yes | Text color of a Marker, in ARGB format. The default value is 0xff000000 (black). |
rotation | number | No | Yes | Rotation angle of the icon of a Marker (only a custom icon is supported). 0 degrees 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, the value 361 would be converted to 1, and the value -1 would be converted to 359. |
Example:
let staticMapMarker: staticMap.StaticMapMarker = {
location: {
latitude: 50,
longitude: 126
},
icon: 'https://icons.iconarchive.com/icons/papirus-team/papirus-apps/48/pingus-icon-icon.png',
font: 'statics',
fontColor: 0xff000000,
rotation: 180,
defaultIconSize: staticMap.IconSize.TINY
}; Defines information of paths to be added to a static 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 API version 4.1.0(11).
System capability: SystemCapability.Map.Core
Start version: 4.1.0(11)
Parameters:
Name | Type | Read-only | Optional | Description |
|---|---|---|---|---|
locations | Array<mapCommon.LatLng> | No | No | Coordinates of a path. |
color | number | No | Yes | Path color, in ARGB format. The default value is 0xff000000 (black). |
fillColor | number | No | Yes | Fill color of a path, in ARGB format. If it is set, the path forms a polygon. |
width | number | No | Yes | Width of a path, in pixels. The default value is 5. |
Example:
let staticMapPath: staticMap.StaticMapPath = {
locations: [
{ latitude: 50, longitude: 126 },
{ latitude: 50.3, longitude: 126 },
{ latitude: 50.3, longitude: 126.3 },
{ latitude: 49.7, longitude: 126 },
{ latitude: 50, longitude: 126 }
],
color: 0xff00ff00,
fillColor: 0xff0000ff,
width: 15
}; Defines the default icon size of a Marker on a static 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 API version 4.1.0(11).
System capability: SystemCapability.Map.Core
Start version: 4.1.0(11)
Name | Value | Description |
|---|---|---|
TINY | 0 | Minimum icon. |
SMALL | 1 | Small icon. |
NORMAL | 2 | Medium-sized icon. |
Example:
let iconSize = staticMap.IconSize.TINY;