文档管理中心

staticMap(静态图)

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

本模块提供获取静态图功能。

起始版本: 4.1.0(11)

导入模块

收起
自动换行
深色代码主题
复制
  1. import { staticMap } from '@kit.MapKit';

getMapImage

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

getMapImage(options: StaticMapOptions): Promise<image.PixelMap>

根据提供的参数创建静态图。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
options StaticMapOptions 静态图参数。

返回值:

展开
类型 说明
Promise<image.PixelMap> Promise对象,返回image.PixelMap,可用于渲染或保存为图片文件。

错误码:

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
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.

示例:

收起
自动换行
深色代码主题
复制
  1. let staticMapOptions: staticMap.StaticMapOptions = {
  2. location: {
  3. latitude: 39.9,
  4. longitude: 116.4
  5. },
  6. zoom: 3,
  7. imageWidth: 10,
  8. imageHeight: 10
  9. };
  10. await staticMap.getMapImage(staticMapOptions);

getMapImage

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

getMapImage(context: common.Context, options: StaticMapOptions): Promise<image.PixelMap>

根据提供的参数创建静态图,支持传入Context上下文。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 5.0.0(12)

参数:

展开
参数名 类型 必填 说明
context common.Context Context上下文。
options StaticMapOptions 静态图参数。

返回值:

展开
类型 说明
Promise<image.PixelMap> Promise对象,返回image.PixelMap

错误码:

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
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.

示例:

收起
自动换行
深色代码主题
复制
  1. let staticMapOptions: staticMap.StaticMapOptions = {
  2. location: {
  3. latitude: 39.9,
  4. longitude: 116.4
  5. },
  6. zoom: 3,
  7. imageWidth: 10,
  8. imageHeight: 10
  9. };
  10. await staticMap.getMapImage(this.getUIContext().getHostContext(), staticMapOptions);

StaticMapOptions

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

StaticMapOptions定义了静态图的参数。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
location mapCommon.LatLng

地图的中心点坐标。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

zoom number

地图的缩放级别,取值范围[2, 17],仅支持整数,小数会被向下取整处理。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

imageWidth number

图片的宽度。

如果scale为1,则取值范围为(0, 1024];如果scale为2,则取值范围为(0, 512]。单位:px。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

imageHeight number

图片的高度。

如果scale为1,则取值范围为(0, 1024];如果scale为2,则取值范围为(0, 512]。单位:px。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

scale number

地图图像分辨率级别,取值为1或2,默认值为1。实际返回图片高度为scale*imageHeight,宽度为scale*imageWidth,单位:px。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

logoAlignment mapCommon.LogoAlignment

地图logo的对齐模式,默认为BOTTOM_START,表示左下角。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

markers Array<StaticMapMarker>

在地图图像上添加标记。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

说明:

网络图标资源的载入会影响网络性能,建议不超过3个。

path StaticMapPath

添加在地图图像上的路径信息。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

dayNightMode mapCommon.DayNightMode

昼夜模式,默认值为mapCommon.DayNightMode.DAY。

起始版本: 5.0.0(12)

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

示例:

收起
自动换行
深色代码主题
复制
  1. let staticMapOptions: staticMap.StaticMapOptions = {
  2. location: {
  3. latitude: 39.9,
  4. longitude: 116.4
  5. },
  6. zoom: 3,
  7. imageWidth: 10,
  8. imageHeight: 10
  9. };

StaticMapMarker

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

StaticMapMarker定义了标记点位置。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
location mapCommon.LatLng 标记点坐标。
icon string

标记点自定义图标,该图标必须以http://或https://开头。如果未设置或者图标不符合要求,系统将使用默认图标。

说明:

图标格式为png,大小不能大于16KB,像素不超过128*128。

defaultIconSize IconSize 默认图标大小。如果使用默认图标,请选择使用默认图标的大小,默认值为IconSize.NORMAL,表示中等大小;如果icon生效,defaultIconSize不生效。
font string 标记点的名称,超长名称超出部分用省略号“...”表示。
fontColor number 标记点文字的颜色,ARGB格式,默认值为0xff000000(黑色)。
rotation number

标记点图标的旋转角度(仅支持自定义图标)。

以正北方向为0度、顺时针方向为正的角度,默认值为0,取值范围:[0, 360]。

示例:

收起
自动换行
深色代码主题
复制
  1. let staticMapMarker: staticMap.StaticMapMarker = {
  2. location: {
  3. latitude: 50,
  4. longitude: 126
  5. },
  6. icon: 'https://icons.iconarchive.com/icons/papirus-team/papirus-apps/48/pingus-icon-icon.png',
  7. font: 'statics',
  8. fontColor: 0xff000000,
  9. rotation: 180,
  10. defaultIconSize: staticMap.IconSize.TINY
  11. };

StaticMapPath

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

StaticMapPath定义了添加到地图图像上的路径信息。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
locations Array<mapCommon.LatLng> 路径的坐标。
color number 指示路径的颜色,ARGB格式,默认值为0xff000000(黑色)。
fillColor number 指示路径的填充颜色,ARGB格式。如果设置fillColor,则路径指示一个多边形。默认值为0x00000000(透明)。
width number 路径的宽度,取值范围:(0, 1024],单位:px,默认值为5px,异常值不处理。

示例:

收起
自动换行
深色代码主题
复制
  1. let staticMapPath: staticMap.StaticMapPath = {
  2. locations: [
  3. { latitude: 50, longitude: 126 },
  4. { latitude: 50.3, longitude: 126 },
  5. { latitude: 50.3, longitude: 126.3 },
  6. { latitude: 49.7, longitude: 126 },
  7. { latitude: 50, longitude: 126 }
  8. ],
  9. color: 0xff00ff00,
  10. fillColor: 0xff0000ff,
  11. width: 15
  12. };

IconSize

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

IconSize定义了静态地图标记的默认图标大小。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Map.Core

起始版本: 4.1.0(11)

展开
名称 说明
TINY 0 最小的图标。
SMALL 1 小图标。
NORMAL 2 中等大小图标。

示例:

收起
自动换行
深色代码主题
复制
  1. let iconSize: staticMap.IconSize = staticMap.IconSize.TINY;
在 API参考 中进行搜索
请输入您想要搜索的关键词