目录

map

Represents the map component.

Before using this component, make preparations by referring to Preparations.

To display the user location on the map, you need to apply for the location permission or use the location component. For details about how to apply for the permission, see Enabling the my-location Icon.

Since: 1.0.0

Related document: has.createMapContext

Attributes

Name Type Default Value Mandatory Description
latitude number 39.908692 Yes

Latitude of the map's center point. The default value is the latitude of Tiananmen.

Note: Use gcj02 for the Chinese mainland and Hong Kong and Macao regions, and use wgs84 for other regions.

longitude number 116.397477 Yes

Longitude of the map's center point. The default value is the longitude of Tiananmen.

Note: Use gcj02 for the Chinese mainland and Hong Kong and Macao regions, and use wgs84 for other regions.

scale number 16 No Zoom level. The value ranges from 2 to 20.
rotate number 0 No

Rotation angle. The value ranges from 0 to 360, in degrees.

Since: 2.0.2

skew number 0 No

Tilt angle. The value ranges from 0 to 40, in degrees.

Since: 2.0.2

min-scale number 2 No

Minimum zoom level. The value ranges from 2 to 20.

Since: 2.0.2

max-scale number 20 No

Maximum zoom level. The value ranges from 2 to 20.

Since: 2.0.2

markers Array<marker> - No Marker. For details, see marker.
circles Array<circle> - No Circle. For details, see circle.
polyline Array<polyline> - No Polyline. For details, see polyline.
polygons Array<polygon> - No

Polygon. For details, see polygon.

Since: 1.0.18

show-location boolean false No Whether to display the current location point.
show-compass boolean false No

Whether to display the compass.

Since: 1.0.18

show-scale boolean false No

Whether to display scale controls.

Since: 2.0.2

enable-rotate boolean false No

Whether to support rotation.

Since: 1.0.18

enable-scroll boolean true No

Whether to support panning.

Since: 1.0.18

enable-zoom boolean true No

Whether to support zooming.

Since: 1.0.18

enable-center-scale boolean false No

Whether to anchor map zooming to the component's center. true: Map zooming is anchored to the component's center. false: Map zooming is anchored to the center point of the user's gesture.

Since: 1.0.19

enable-zoom-controls boolean false No

Whether to enable the map zooming controller. true: The map zooming controller is enabled. false: The map zooming controller is disabled.

Since: 2.0.2

enable-overlooking boolean false No

Whether to enable tilt gestures.

- When enabled, users can use two fingers to swipe up or down vertically to tilt the camera.

- When disabled, users cannot tilt the camera through tilt gestures.

Since: 2.0.2

enable-traffic boolean false No

Whether to enable real-time traffic. true: Real-time traffic is enabled. false: Real-time traffic is disabled.

Since: 2.0.2

include-points Array<point> - No

Whether to zoom in on the map to show all given coordinates.

Parameter format: [{latitude: 0, longitude: 0}, {latitude: 1, longitude: 1}]

Since: 2.0.2

subkey string - No

Custom style ID. If the ID is invalid, the system style is used. The value cannot be dynamically updated. For details about how to obtain the ID, see step 2 in "Setting the Style ID" in Displaying a Custom Map.

Since: 2.0.2

setting Object - No

Attribute configuration item. For details, see setting.

Since: 2.0.2

bindtap event - No Event triggered when the map is tapped.
bindmarkertap event - No Event triggered when a marker is tapped. The format is e.detail = {markerId}.
bindupdated event - No Event triggered when map rendering update is complete.
bindregionchange event - No

Event triggered when the field of view changes.

Since: 1.0.8

bindcallouttap event - No

Event triggered when the callout corresponding to the marker is tapped. The format is e.detail = {markerId}.

Since: 1.0.10

bindpolylinetap event - No

Event triggered when a polyline on the map is tapped. The format is e.detail = {polylineId}.

Since: 2.0.2

bindpoitap event - No

Event triggered when a POI on the map is tapped. The format is e.detail = {name, longitude, latitude}.

Since: 2.0.2

binderror event - No

Event triggered when the map fails to be created or the map service is abnormal. The format is e.detail = {errCode, errMsg}.

Since: 2.0.2

Return values of bindregionchange

Name Type Description
type string

Event type.

begin: triggered when the field of view begins to change.

end: triggered when the field of view finishes changing.

causedBy string

Reason why the field of view changes.

The value of causedBy returned in the begin phase:

1. gesture: gesture.

2. update: API call.

The value of causedBy returned in the end phase:

1. drag: dragging the map.

2. scale: scaling the map.

3. update: API call.

Error code information

Error Code Error Message Description
40001 Failed to create map. Failed to create the map.
40002 Map service unavailable. The map service is abnormal.

marker

Name Type Default Value Mandatory Description
id number - Yes Marker ID. This ID will be returned when the marker tap event is called back.
latitude number - Yes

Latitude. The value is a floating point number ranging from –90 to 90.

Note: Use gcj02 for the Chinese mainland and Hong Kong and Macao regions, and use wgs84 for other regions.

longitude number - Yes

Longitude. The value is a floating point number ranging from –180 to 180.

Note: Use gcj02 for the Chinese mainland and Hong Kong and Macao regions, and use wgs84 for other regions.

title string - No

Marker title, which is displayed when a marker is tapped.

Since 1.0.10, the callout property is supported. If callout exists, title will be ignored.

zIndex number - No Display level.
iconPath string - Yes

Icon path, which can be a network path, local path, or code package path.

In versions earlier than ASCF 2.0.1, the image is displayed based on the original dimensions by default. In ASCF 2.0.1 and later versions, the image is displayed based on the dimensions calculated based on the current screen density by default.

rotate number 0 No Rotation angle in the clockwise direction. The value ranges from 0 to 360. The default value is 0.
alpha number 1 No Annotation alpha. The value ranges from 0 to 1. The default value is 1, indicating no transparency.
width number - No

Actual image width by default. The unit can be rpx or px. The default unit is px.

Since: 2.0.2

height number - No

Actual image height by default. The unit can be rpx or px. The default unit is px.

Since: 2.0.2

anchor Object - No Anchor of a marker icon, which corresponds to a specific pair of latitude and longitude. The default value is the midpoint of the icon bottom edge. The value format is {x, y}, where x indicates the horizontal position, with a value range of 0 to 1, and y indicates the vertical position, with a value range of 0 to 1. For example, {x: 0.5, y: 1} indicates the midpoint of the icon bottom edge.
clickable boolean true No Whether a marker is tappable. The default value is true. If an invalid value is passed, the default value will be used. true: yes; false: no.
callout Object - No

Callout displayed above the marker. For details, see Callout on a Marker.

Since: 1.0.10

label Array<Object> - No

Label added next to the marker. For details, see Label on a Marker.

Since: 1.0.10

customCallout Object - No

Custom callout. For details, see Custom Callout on a Marker.

Since: 1.0.22

Callout on a Marker

Name Type Default Value Mandatory Description
content string - No Text.
padding number|string 0 No Text padding, in rpx or px (default).
bgColor string #FFFFFF (white) No Background color.
color string #000000 (black) No Text color.
fontSize number|string 15 No Text size, in rpx or px (default).
weight string Normal No

Font weight.

Valid values:

Lighter: thinner than Normal

Normal: standard font weight

Regular: same as Normal

Medium: slightly thicker than Normal

Bold: significantly thicker

Bolder: extremely thick

fontStyle string Normal No

Title font style.

Valid values:

Normal: standard font style

Italic: italic

textAlign string center No

Text alignment mode.

Valid values:

Start: left-aligned

End: right-aligned

Center: centered

borderWidth number|string 0 No Border width, in rpx or px (default).
borderColor string #FFFFFF (white) No Border color.
borderRadius number|string 0 No Border radius, in rpx or px (default).
anchorX number 0 No

Horizontal offset. A positive number indicates the right direction. The unit can be rpx or px (default).

Since: 2.0.2

anchorY number 0 No

Vertical offset. A positive number indicates the downward direction. The unit can be rpx or px (default).

Since: 2.0.2

Label on a Marker

Name Type Default Value Mandatory Description
content string - Yes Text.
color string #000000 (black) No Title font color.
fontSize number|string 15 No Font size of the title, in rpx or px (default).
strokeColor string #FFFFFF (white) No Title stroke color.
strokeWidth number|string 2 No Stroke width of the title. The value must be greater than 0 and less than or equal to 10, in rpx or px (default).
fontStyle string REGULAR No

Title font style.

Valid values:

REGULAR: normal

BOLD: bold

ITALIC: italic

BOLD_ITALIC: bold italic

MEDIUM: medium

MEDIUM_ITALIC: medium italic

anchorX number 0 No

Horizontal offset. A positive number indicates the right direction. The unit can be rpx or px (default).

Since: 2.0.2

anchorY number 0 No

Vertical offset. A positive number indicates the downward direction. The unit can be rpx or px (default).

Since: 2.0.2

Custom Callout on a Marker

Name Type Default Value Mandatory Description
display string BYCLICK No

Callout display status.

Valid values:

BYCLICK: displayed upon a tap.

ALWAYS: always displayed.

anchorX number 0 No Horizontal offset. A positive number indicates the right direction. The unit can be rpx or px (default).
anchorY number 0 No Vertical offset. A positive number indicates the downward direction. The unit can be rpx or px (default).

Add a slot named callout to the map component. The cover-view component inside the slot is bound to the marker through the marker-id attribute. When a marker is created, the content displayed in the cover-view component is displayed as a callout above the marker.

<map>
  <cover-view slot="callout">
    <cover-view marker-id="1"></cover-view>
    <cover-view marker-id="2"></cover-view>
  </cover-view>
</map>

Constraints:

polygon

Name Type Default Value Mandatory Description
points array - Yes Longitude and latitude array, in the format of [{latitude: 0, longitude: 0}].
strokeWidth number|string 1 No

Stroke width, in rpx or px. The default value is vp.

Note: If no pixel unit is specified for a string, the default unit is vp. For example, '10' is equivalent to 10 vp. If a number is passed, the default unit is vp.

strokeColor string #0A59F7CC No Stroke color.
fillColor string #0A59F71A No Fill color.
zIndex number - No Z-axis index of the polygon.

circle

Name Type Default Value Mandatory Description
latitude number - Yes

Latitude. The value is a floating-point number ranging from –90 to 90.

Note: Use gcj02 for the Chinese mainland and Hong Kong and Macao regions, and use wgs84 for other regions.

longitude number - Yes

Longitude. The value is a floating-point number ranging from –180 to 180.

Note: Use gcj02 for the Chinese mainland and Hong Kong and Macao regions, and use wgs84 for other regions.

color string #000000ff No Stroke color.
fillColor string #00000000 No Fill color.
radius number - Yes Radius of a circle, in meters.
strokeWidth number|string 1 No

Stroke width, in rpx or px. The default value is vp.

Note: If no pixel unit is specified for a string, the default unit is vp. For example, '10' is equivalent to 10 vp. If a number is passed, the default unit is vp.

zIndex number - No Z-axis index, which is used to describe element overlapping relationships.

polyline

Name Type Default Value Mandatory Description
id number - No

Polyline ID (used when a MapContext.eraseLines polyline is removed).

Since: 2.0.2

points array - Yes

Longitude-latitude array, which is in the [{latitude: 0, longitude: 0}] format.

Note: Use gcj02 for the Chinese mainland and Hong Kong and Macao regions, and use wgs84 for other regions.

width number|string 1 No

Width of a polyline, in rpx or px. The default unit is vp.

Note: If no pixel unit is specified for a string, the default unit is vp. For example, '10' is equivalent to 10 vp. If a number is passed, the default unit is vp.

color string "#000000ff" No Color of a polyline.
dottedLine boolean false No Whether the polyline is a dotted line.
arrowLine boolean false No

Whether the polyline is with an arrow.

Since: 2.0.2

arrowIconPath string - No

Icon path of the arrow, which can be a network path, local path, or code package path. This parameter takes effect only when arrowLine is set to true.

Since: 2.0.2

zIndex number - No Z coordinate.

setting

This parameter is used to configure map attributes in a unified manner. This solves the problem that animation attributes such as rotate and skew cannot take effect at the same time when they are set separately.

this.setData({
  // Only the attributes that are set take effect, and other attributes are not affected.
  setting: {
    skew: 20,
    rotate: 90,
    showLocation: true,
    enableOverlooking: true,
    enableTraffic: true
  }
});

Example: