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:
| Properties | Type | Default value | Required | Description | iOS support | Android support | IDE support |
|---|---|---|---|---|---|---|---|
| type | string | tencent | No | Map type, tencent or google | No | No | Yes |
| longitude | number | - | Yes | Center longitude | Yes | Yes | Yes |
| latitude | number | - | Yes | Center latitude | Yes | Yes | Yes |
| scale | number | 16 | No | Zoom level, value range is 3 to 20 | Yes | Yes | Yes |
| min-scale | number | 3 | No | Minimum zoom level | Yes | Yes | |
| max-scale | number | 20 | No | Maximum zoom level | Yes | Yes | |
| markers | array.marker | - | No | Marker point | Yes | Yes | Yes |
| polyline | array.polyline | - | No | Route | Yes | Yes | Yes |
| circles | array.circle | - | No | Circle | Yes | Yes | Yes |
| controls | Array.control | - | No | Control (to be abandoned, it is recommended to use cover-view instead) | No | No | No |
| include-points | array.point | - | No | Zoom the field of view to include all given coordinate points | Yes | Yes | Yes |
| show-location | boolean | false | No | Show the current location point with direction | Yes | Yes | Yes |
| polygons | array.polygon | - | No | Polygon | Yes | Yes | Yes |
| subkey | string | - | No | Key used by personalized map | No | No | Yes |
| layer-style | number | 1 | No | Map capability [Personalized map] configuration style | No | No | No |
| rotate | number | 0 | No | Rotation angle, range 0 ~ 360, the angle between the true north of the map and the y-axis of the device | No | Yes | No |
| skew | number | 0 | No | Tilt angle, range 0 ~ 40, the tilt angle about the z-axis | System map: No Tencent map: Yes Baidu map: Yes Amap: Yes | Yes | No |
| enable-3D | boolean | false | No | Show 3D building blocks | System 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-compass | boolean | false | No | Show compass | Yes | Yes | No |
| show-scale | boolean | false | No | Show scale | Yes | Google map: No Huawei map: No Tencent map: Yes Baidu map: Yes Amap: Yes | Yes |
| enable-overlooking | boolean | false | No | Turn on bird's eye view | System map: No Tencent map: Yes Baidu map: Yes Amap: Yes | Yes | No |
| enable-zoom | boolean | true | No | Support zooming | View container. | View container. | Yes |
| enable-scroll | boolean | true | No | Support dragging | View container. | Yes | Yes |
| enable-rotate | boolean | - | No | Support rotation | Yes | Yes | No |
| enable-satellite | boolean | false | No | Support satellite image | Yes | Google map: Yes Huawei map: No Tencent map: Yes Baidu map: Yes Amap: Yes | Yes type=google |
| enable-traffic | boolean | false | No | Support real-time traffic conditions | Yes | Yes | Yes |
| enable-poi | boolean | true | No | Show POI points | System 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-building | boolean | false | No | Show buildings | System 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, clear | View container. type=google |
| setting | object | - | No | Configuration items | No | No | Yes |
| bindtap | eventhandle | - | No | Triggered when clicking the map, returns longitude and latitude information | Yes | Yes | Yes |
| bindlabeltap | eventhandle | - | No | Triggered when clicking a marker point e.detail = {markerId} | Yes | Yes | Yes |
| bindmarkertap | eventhandle | - | No | Triggered when clicking a label, e.detail = {markerId} | Yes | No | Yes type=tencent |
| bindcontroltap | eventhandle | - | No | Triggered when clicking a control, e.detail = {controlId} | No | No | No |
| bindcallouttap | eventhandle | - | No | Triggered when clicking the bubble corresponding to the marker point e.detail = {markerId} | No | No | Yes |
| bindupdated | eventhandle | - | No | Triggered when the map rendering update is completed | Yes | Yes | Yes |
| bindregionchange | eventhandle | - | No | Triggered when the field of view changes | Yes | Yes | Yes |
| bindpoitap | eventhandle | - | No | Triggered when clicking on a map poi point, e.detail = {name, longitude, latitude} | No | Yes | Yes |
| bindanchorpointtap | eventhandle | - | No | Triggered when clicking on a location marker, e.detail = {longitude, latitude} | No | No | No |
TIP
- (Color values in the map, such as color/borderColor/bgColor, need to be represented using 6-digit (8-digit) hexadecimal notation. In 8-digit notation, the last two digits represent the alpha value, e.g., #000000AA.points) Structural Attributes
- 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
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.
// 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.
Huawei map: Yes
Tencent map: Yes
Baidu map: Yes
Amap: No
Callout bubble on marker
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.
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.
<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
| Properties | Type | Default value | iOS support | Android support | IDE support |
|---|---|---|---|---|---|
| content | Text | string | No | No | Yes |
| color | Text color | string | No | No | Yes |
| fontSize | Text size | number | No | No | Yes |
| anchorX | The coordinates of the label, the origin is the latitude and longitude corresponding to the marker | number | No | No | Yes |
| anchorY | The coordinates of the label, the origin is the latitude and longitude corresponding to the marker | number | No | No | Yes |
| borderWidth | Border width | number | No | No | Yes |
| borderColor | Border color | string | No | No | Yes |
| borderRadius | Border radius | number | No | No | Yes |
| bgColor | Background color | string | No | No | Yes |
| padding | Text compilation blank | number | No | No | Yes |
| textAlign | Text alignment. Valid values: left, right, center | string | No | No | Yes |
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:
- MapContext.addMarkers Specify the markers involved in the aggregation.
- (Optional) When MapContext.on('markerClusterCreate', callback) is triggered, MapContext.addMarkers Update the style of the cluster.
- MapContext.removeMarkers Remove the markers involved in the aggregation.
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.

SegmentText
| Properties | Description | Type |
|---|---|---|
| name | Name | string |
| startIndex | Starting point | number |
| endIndex | End point | number |
TextStyle
| Properties | Description | Type | Default value |
|---|---|---|---|
| textColor | Text color | string | #000000 |
| strokeColor | Stroke color | number | #ffffff |
| fontSize | Text size | number | 14 |
| Value | Description |
|---|---|
| abovelabels | Display above all POIs |
| abovebuildings | Display above the building block and below the POI |
| aboveroads | Display 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

circle
- Function Description: Display a circle on the map

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