Skip to content

Map Component

map

  • Function Description:Map, this component is Native Component , please pay attention to the relevant restrictions when using it, and the relevant API can be found in wx.createMapContext

  • Support Description::

  • System Map: Only supported by iOS.

  • Google Map: Android support, IDE support.

  • Huawei Map: Only supported by Android.

  • Tencent Map: IOS support, Android support, IDE support.

  • Parameters and descriptions:

PropertiesTypeDefault valueRequiredDescriptioniOS supportAndroid supportIDE support
typestringtencentNoMap type, tencent or googleNoNoYes
longitudenumber-YesCenter longitudeYesYesYes
latitudenumber-YesCenter latitudeYesYesYes
scalenumber16NoZoom level, value range is 3 to 20YesYesYes
min-scalenumber3NoMinimum zoom levelYesYes
max-scalenumber20NoMaximum zoom levelYesYes
markersarray.marker-NoMarker pointYesYesYes
polylinearray.polyline-NoRouteYesYesYes
circlesarray.circle-NoCircleYesYesYes
controlsArray.control-NoControl (to be abandoned, it is recommended to use cover-view instead)NoNoNo
include-pointsarray.point-NoZoom the field of view to include all given coordinate pointsYesYesYes
show-locationbooleanfalseNoShow the current location point with directionYesYesYes
polygonsarray.polygon-NoPolygonYesYesYes
subkeystring-NoKey used by personalized mapNoNoYes
layer-stylenumber1NoMap capability [Personalized map] configuration styleNoNoNo
rotatenumber0NoRotation angle, range 0 ~ 360, the angle between the true north of the map and the y-axis of the deviceNoYesNo
skewnumber0NoTilt angle, range 0 ~ 40, the tilt angle about the z-axisSystem map: No
Tencent map: Yes
Baidu map: Yes
Amap: Yes
YesNo
enable-3DbooleanfalseNoShow 3D building blocksSystem map: No
Tencent map: Yes
Baidu map: No
Amap: No
Google map: Yes
Huawei map: Yes
Tencent map: Yes
Baidu map: Yes
Amap: No
No
show-compassbooleanfalseNoShow compassYesYesNo
show-scalebooleanfalseNoShow scaleYesGoogle map: No
Huawei map: No
Tencent map: Yes
Baidu map: Yes
Amap: Yes
Yes
enable-overlookingbooleanfalseNoTurn on bird's eye viewSystem map: No
Tencent map: Yes
Baidu map: Yes
Amap: Yes
YesNo
enable-zoombooleantrueNoSupport zoomingView container.View container.Yes
enable-scrollbooleantrueNoSupport draggingView container.YesYes
enable-rotateboolean-NoSupport rotationYesYesNo
enable-satellitebooleanfalseNoSupport satellite imageYesGoogle map: Yes
Huawei map: No
Tencent map: Yes
Baidu map: Yes
Amap: Yes
Yes type=google
enable-trafficbooleanfalseNoSupport real-time traffic conditionsYesYesYes
enable-poibooleantrueNoShow POI pointsSystem map: No
Tencent map: Yes
Baidu map: Yes
Amap: No
Google map: Yes
No
Tencent map: Yes
Baidu map: Yes
Amap: Yes
View container. type=google
enable-buildingbooleanfalseNoShow buildingsSystem map: No
System map: Yes
Tencent map: No
Tencent map: Yes
The type of icon, valid values: success, success_no_circle, info, warn, waiting, cancel, download, search, clearView container. type=google
settingobject-NoConfiguration itemsNoNoYes
bindtapeventhandle-NoTriggered when clicking the map, returns longitude and latitude informationYesYesYes
bindlabeltapeventhandle-NoTriggered when clicking a marker point e.detail = {markerId}YesYesYes
bindmarkertapeventhandle-NoTriggered when clicking a label, e.detail = {markerId}YesNoYes type=tencent
bindcontroltapeventhandle-NoTriggered when clicking a control, e.detail = {controlId}NoNoNo
bindcallouttapeventhandle-NoTriggered when clicking the bubble corresponding to the marker point e.detail = {markerId}NoNoYes
bindupdatedeventhandle-NoTriggered when the map rendering update is completedYesYesYes
bindregionchangeeventhandle-NoTriggered when the field of view changesYesYesYes
bindpoitapeventhandle-NoTriggered when clicking on a map poi point, e.detail = {name, longitude, latitude}NoYesYes
bindanchorpointtapeventhandle-NoTriggered when clicking on a location marker, e.detail = {longitude, latitude}NoNoNo

TIP

  • The color values
  • The longitude and latitude of the map component are required.
  • The longitude and latitude used by the map component are the Martian coordinate system. When calling the wx.getLocation interface, you need to specify type as gcj02.

regionchange Return value:

When the field of view changes, regionchange will be triggered twice, and the returned type values

  • The begin stage returns causedBy: valid values
  • The end stage returns causedBy: valid values
js
e = {
  causedBy,
  type,
  detail: { rotate, skew, scale, centerLocation, region },
};

setting

Provide setting objects to uniformly set map configurations. At the same time, for some animation properties such as rotate and skew, they cannot take effect at the same time when set separately through setData, and need to be modified uniformly through settting.

js
// Default values
const setting = {
  rotate: 0,
  showLocation: false,
  subKey: "",
  layerStyle: 1,
  enableZoom: true,
  enableScroll: true,
  enableRotate: false,
  showCompass: false,
  enableSatellite: false,
};

this.setData({
  // Changes only affect the properties involved in the setting object; other properties remain unaffected.
  setting: {
    enableZoom: false,
    enableScroll: false,
  },
});

marker

Mark point, used to display the location of the mark on the map.

Properties
Type
Default value
Required
Description
iOS support
Android support
IDE support
id
Mark point id
number
No
The marker click event callback will return this id. It is recommended to set an ID for each marker to ensure better performance when updating the marker.
Yes
Yes
Yes
clusterId
Cluster ID
number
No
Used when customizing point cluster effects
No
No
No
joinCluster
Whether to participate in point aggregation
boolean
No
Default is not to participate in point aggregation
No
Google map: Yes
Huawei map: Yes
Tencent map: Yes
Baidu map: Yes
Amap: No
No
latitude
Latitude
number
Yes
Floating point number, range -90 ~ 90
Yes
Yes
Yes
longitude
Longitude
number
Yes
Floating point number, range -90 ~ 90
Yes
Yes
Yes
title
Point name
string
No
Displayed when clicked, ignored when callout exists
Yes
Yes
Yes type=tencent
zIndex
Display level
number
No
-
No
Yes
Yes
iconPath
Displayed icon
string
Yes
Image path under the project directory, supports network path, local path, code package path
Yes
Yes
Yes
rotate
Rotation angle
number
No
Clockwise rotation angle, range 0~360, default is 0
No
Yes
Yesype=tencent
alpha
Transparency of annotation
number
No
Default is 1, no transparency, range 0~1
No
Yes
Yesype=tencent
width
Annotation icon width
number/string
No
Default is the actual width of the image
No
Yes
No
height
Annotation icon height
number/string
No
Default is the actual height of the image
No
Yes
No
callout
Bubble window above the marker point
object
No
Supported properties are shown in the table below, line breaks can be recognized
Yes
Yes
Yes
customCallout
Custom bubble window
object
No
Supported properties are shown in the table below
No
No
No
label
Add a label next to the marker point
object
No
Supported properties are shown in the table below, line breaks can be recognized
No
No
Yes
anchor
Longitude and latitude are at the anchor point of the annotation icon, default is the bottom midpoint
object
No
{x, y}, x represents horizontal direction (0-1), y represents vertical direction (0-1). {x: .5, y: 1} represents the midpoint of the bottom edge
No
Yes
No

Callout bubble on marker

Properties
Description
Type
iOS support
Android support
IDE support
content
Text
string
Yes
Yes
Yes
color
Text color
string
No
Yes
Yes
fontSize
Text size
number
No
Yes
Yes
borderRadius
Border radius
number
No
Yes
Yes
borderWidth
Border width
number
No
Yes
Yes
borderColor
Border color
string
No
Yes
Yes
bgColor
Background color
string
No
Yes
Yes
padding
Text compilation blank
number
No
Yes
Yes
display
'BYCLICK': click to display; 'ALWAYS': always display
string
No
No
Yes
textAlign
Text alignment. Valid values: left, right, center
string
No
Yes
No
anchorX
Horizontal offset, positive number to the right
number
No
Google map: Yes
Huawei map: Yes
Tencent map: Yes
Baidu map: No
Amap: Yes
No
anchorY
Vertical offset, positive number to the bottom
number
No
Google map: Yes
Huawei map: Yes
Tencent map: Yes
Baidu map: No
Amap: Yes
No

Custom bubble on marker customCallout

When customCallout exists, callout and title attributes will be ignored. Custom bubble is customized using cover-view, which is more flexible.

Properties
Type
Default value
iOS support
Android support
IDE support
display
'BYCLICK': click to display; 'ALWAYS': always display
string
No
No
No
anchorX
Horizontal offset, positive number to the right
number
No
No
No
anchorY
Vertical offset, positive number to the bottom
number
No
No
No

Usage is as follows: add a slot node named callout under the map component, and its internal cover-view is bound to the marker through the marker-id attribute. When the marker is created, the content displayed by the cover-view will be displayed above the marker as a callout.

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

Bubble label on the marker

PropertiesTypeDefault valueiOS supportAndroid supportIDE support
contentTextstringNoNoYes
colorText colorstringNoNoYes
fontSizeText sizenumberNoNoYes
anchorXThe coordinates of the label, the origin is the latitude and longitude corresponding to the markernumberNoNoYes
anchorYThe coordinates of the label, the origin is the latitude and longitude corresponding to the markernumberNoNoYes
borderWidthBorder widthnumberNoNoYes
borderColorBorder colorstringNoNoYes
borderRadiusBorder radiusnumberNoNoYes
bgColorBackground colorstringNoNoYes
paddingText compilation blanknumberNoNoYes
textAlignText alignment. Valid values: left, right, centerstringNoNoYes

Point aggregation

  • Function DescriptionWhen there are too many markers that need to be displayed on the map, the markers on the interface may be overlapped, the display is incomplete, and the overall performance deteriorates. To address this problem, the point aggregation capability is introduced.

  • System map (only supported by iOS)

    The usage process is as follows:

  • Google Maps (only supported by Android)

    To use it, specify joinCluster when adding a marker. The markers that meet the conditions will be automatically aggregated.

polyline

  • Function DescriptionSpecify a series of coordinate points, connect the first item in the array to the last item. When drawing a rainbow line, you need to specify the colors of different segments. For example, if points contains 5 points, then colorList should pass in 4 color values; if the length of colorList is less than points.length - 1, the colors of the remaining segments will be consistent with the last item.

Properties
Type
Default value
Required
Remarks
iOS support
Android support
IDE support
points
Array of longitude and latitude
Array
Yes
[{latitude: 0, longitude: 0}]
Yes
Yes
Yes
color
Line color
string
No
Hexadecimal
Yes
Yes
Yes
colorList
Rainbow line
Array
No
Ignore color value if it exists
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: Yes
Amap: Yes
No
width
Line width
number
No
Yes
Yes
Yes
dottedLine
Is it a dotted line?
boolean
No
Default is false
Yes
Yes
Yes
arrowLine
Is it a dotted line?
boolean
No
-
No
Yes
No
arrowIconPath
Change arrow icon
string
No
-
No
Yes
No
borderColor
Line border color
string
No
-
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: No
Amap: No
Yes
borderWidth
Line thickness
number
No
-
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: No
Amap: No
Yes
level
Overlap relationship
string
No
Default is abovelabels
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: No
Amap: No
No
textStyle
Text style
TextStyle
No
Text style on polyline
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: No
Amap: No
No
segmentTexts
Segment text
Array.SegmentText
No
Text content and position on polyline
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: No
Amap: No
No

SegmentText

PropertiesDescriptionType
nameNamestring
startIndexStarting pointnumber
endIndexEnd pointnumber

TextStyle

PropertiesDescriptionTypeDefault value
textColorText colorstring#000000
strokeColorStroke colornumber#ffffff
fontSizeText sizenumber14
The level field indicates the overlapping relationship with other map elements. The optional values
ValueDescription
abovelabelsDisplay above all POIs
abovebuildingsDisplay above the building block and below the POI
aboveroadsDisplay above the road and below the building block

polygon

  • DescriptionSpecify a series of coordinate points and generate a closed polygon based on the points coordinate data

Properties
Description
Default value
Required
Remarks
iOS support
Android support
IDE support
dashArray
Dash line
Array.number
No
The default value [0, 0] is a solid line, and [10, 10] is a dashed line consisting of 10 pixels of solid line and 10 pixels of blank space (and so on)
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: No
Amap: No
No
points
Array of longitude and latitude
array
Yes
[{latitude: 0, longitude: 0}]
Yes
Yes
Yes
strokeWidth
Stroke width
number
No
-
Yes
Yes
No
strokeColor
Stroke color
string
No
Hexadecimal
Yes
Yes
No
fillColor
Fill color
string
No
Hexadecimal
Yes
Yes
Yes
zIndex
Set the Z axis value of the polygon
number
No
-
No
Yes
Yes
level
Overlap relationship
string
Yes
Default is abovelabels
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: No
Amap: No
No

circle

  • Function Description: Display a circle on the map

Properties
Description
Default value
Required
Remarks
iOS support
Android support
IDE support
latitude
Latitude
number
Yes
The default value [0, 0] is a solid line, and [10, 10] is a dashed line consisting of 10 pixels of solid line and 10 pixels of blank space (and so on)
Yes
Yes
Yes
longitude
Longitude
number
Yes
Floating point number, range -180 ~ 180
Yes
Yes
Yes
color
Stroke color
string
No
Floating point number, range -180 ~ 180
Yes
Yes
Yes
fillColor
Fill color
string
No
Hexadecimal
Yes
Yes
Yes
radius
Radius
number
No
-
Yes
Yes
Yes
strokeWidth
Stroke width
number
No
-
Yes
Yes
No
level
Overlap relationship
string
Yes
Default is abovelabels
No
Google map: No
Huawei map: No
Tencent map: Yes
Baidu map: No
Amap: No
No

control

  • Display the control on the map. The control does not move with the map and will be abandoned soon. It is recommended to use cover-view
Properties
Type
Default value
Required
Remarks
iOS support
Android support
IDE support
id
Control id
number
No
This id will be returned when the control is clicked
No
No
No
position
The location of the control on the map
object
Yes
The location of the control on the map
No
No
No
iconPath
Displayed icon
string
Yes
Image path in the project directory, supports local path and code package path
No
No
No
clickable
Is it clickable
boolean
No
Not clickable by default
No
No
No

position

Properties
Type
Default value
Required
Remarks
iOS support
Android support
IDE support
left
How far from the left border of the map
number
No
Default is 0
No
No
No
top
How far from the upper border of the map
number
No
Default is 0
No
No
No
width
Width of space
number
No
Default is image width
No
No
No
height
Height of space
number
No
Default is image height
No
No
No

bindregionchange return value

Properties
Description
Type
Remarks
type
Triggered when the field of view changes at the beginning and end
string
Field of view changes start with begin and end with end
causedBy
Causes of field of view changes
string
Drag the map (drag), zoom (scale), call the interface (update)

Scale

scale
3
4
5
6
7
8
9
10
11
Scale
1000km
500km
200km
100km
50km
25km
20km
10km
5km
scale
12
13
14
15
16
17
18
19
20
Scale
2km
1km
500m
200m
100m
50m
20m
10m
5m