This API is used via wx.createMapContext(string mapId, Object this).
<!-- map.wxml --><map id="myMap" show-location /><button type="primary" bindtap="getCenterLocation">Get location</button><button type="primary" bindtap="moveToLocation">Change location</button><button type="primary" bindtap="translateMarker">Move Marker</button><button type="primary" bindtap="includePoints">Scale the field of view to display all longitudes and latitudes.</button>
// map.jsPage({onReady: function (e) {// Use wx.createMapContext to get map context.this.mapCtx = wx.createMapContext('myMap')},getCenterLocation: function () {this.mapCtx.getCenterLocation({success: function(res){console.log(res.longitude)console.log(res.latitude)}})},moveToLocation: function () {this.mapCtx.moveToLocation()},translateMarker: function() {this.mapCtx.translateMarker({markerId: 0,autoRotate: true,duration: 1000,destination: {latitude:23.10229,longitude:113.3345211,},animationEnd() {console.log('animation end')}})},includePoints: function() {this.mapCtx.includePoints({padding: [10],points: [{latitude:23.10229,longitude:113.3345211,}, {latitude:23.00229,longitude:113.3345211,}]})}})
The method is used via MapContext.addArc(Object object).
Attribute | Type | Default value | Required | Description |
id | number | - | Yes | Arc ID |
start | Object | - | Yes | Start point |
end | Object | - | Yes | End point |
pass | Object | - | No | Waypoint |
angle | number | 0 | No | Included Angle |
width | number | 5 | No | Line Width |
color | number | #000000 | No | Color of the line |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
The method is used via : MapContext.addCustomLayer(Object object)
Attribute | Type | Default value | Required | Description |
layerId | string | - | Yes | ID of personalized layer. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
The method is used via MapContext.addGroundOverlay(Object object).
Attribute | Type | Default value | Required | Description |
id | String | - | Yes | ID of image layer |
src | String | - | Yes | Image path, supporting network images, temporary paths, and code package paths. |
bounds | Object | - | Yes | Longitude and latitude range covered by the image |
visible | Boolean | true | No | Visible or not |
zIndex | Number | 1 | No | Layer Rendering Sequence |
opacity | Number | 1 | No | Layer Transparency |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Structure attributes | Type | Default value | Required | Description |
southwest | Object | - | Yes | Southwest corner's longitude and latitude |
northeast | Object | - | Yes | Northeast corner's longitude and latitude |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
The method is used via MapContext.addMarkers(Object object).
Attribute | Type | Default value | Required | Description |
markers | array | - | Yes | Same as the marker attribute passed into the map component. |
clear | boolean | false | No | Whether to clear all markers on the map first. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
The method is used via MapContext.eraseLines(Object object).
Attribute | Type | Default value | Required | Description |
lines | Array.<Object> | - | Yes | |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Structure attributes | Type | Default value | Required | Description |
id | number | - | Yes | Line segment ID |
index | number | - | Yes | Specifies a section of the line segment, with the starting point index of the line being 0. |
point | Object | - | Yes | Specifies a point within a section of the line segment. |
clear | boolean | true | No | True for erasure, false for graying out. |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
The method is used via MapContext.fromScreenLocation(Object object).
Attribute | Type | Default value | Required | Description |
x | number | - | Yes | X-coordinate value. |
y | number | - | Yes | Y-coordinate value. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
latitude | number | Latitude |
longitude | number | Longitude |
This method is used via MapContext.getCenterLocation(Object object).
Attribute | Type | Default value | Required | Description |
iconPath | string | - | No | Image path, supporting network paths, local paths, and code package paths. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
longitude | number | Longitude |
latitude | number | Latitude |
This method is used via MapContext.getRegion(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
southwest | object | Southwest corner's longitude and latitude |
northeast | object | Northeast corner's longitude and latitude |
Structure attributes | Type | Description |
longitude | number | Longitude |
latitude | number | Latitude |
Structure attributes | Type | Description |
longitude | number | Longitude |
latitude | number | Latitude |
This method is used via MapContext.getRotate(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
rotate | number | Rotation Angle |
This method is used via MapContext.getScale(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
scale | number | Scaling value |
This method is used via MapContext.getSkew(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
skew | number | Tilt Angle |
The method is used via MapContext.includePoints(Object object).
Attribute | Type | Default value | Required | Description |
points | array. | - | Yes | List of coordinate points to be displayed within the visible area. |
padding | array. | - | No | The distance from the edges of the rectangle formed by the coordinate points to the edge of the map, measured in pixels. The format is [top, right, bottom, left]. On Android, only the first item in the array can be recognized, and the padding for top, bottom, left, and right is consistent. The developer tool does not currently support the padding parameter. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
The method is used via MapContext.initMarkerCluster(Object object).
Attribute | Type | Default value | Required | Description |
enableDefaultStyle | boolean | true | No | Enable the default clustering style. |
zoomOnClick | boolean | true | No | Whether to implement cluster separation when a clustered marker point is clicked. |
gridSize | number | 60 | No | The aggregatable distance (measured in pixels) for the clustering algorithm, that is, points closer than this value will be clustered together. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via MapContext.moveAlong(Object object).
Attribute | Type | Default value | Required | Description |
markerId | number | - | Yes | Specify a marker. |
path | array | - | Yes | The coordinate string of the moving path, with the coordinate point format being {longitude, latitude} . |
autoRotate | boolean | true | No | Automatically adjust the rotation angle of the marker based on the path direction. |
duration | number | - | Yes | The duration of smooth movement. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via MapContext.moveToLocation(Object object).
Attribute | Type | Default value | Required | Description |
longitude | number | - | No | Longitude |
latitude | number | - | No | Latitude |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via MapContext.on(string event, function callback).
Parameter | Type | Description |
layerId | String | Layer ID |
eventType | String | Event type |
eventInfo | String | Event information |
Parameter | Type | Description |
clusters | Array<ClusterInfo> | Cluster data |
Parameter | Type | Description |
cluster | ClusterInfo | Cluster |
Parameter | Type | Description |
clusterId | Number | Cluster ID |
center | LatLng | Cluster coordinates |
markerIds | Array<Number> | Array of point marker data within the aggregation cluster |
MapContext.on('visualLayerEvent', (res) => {})MapContext.on('markerClusterCreate', (res) => {})MapContext.on('markerClusterClick', (res) => {})
This method is used via MapContext.openMapApp(Object object).
Attribute | Type | Default value | Required | Description |
longitude | number | - | Yes | Destination Longitude |
latitude | number | - | Yes | Destination Latitude |
destination | string | - | Yes | Destination Name |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via MapContext.removeArc(Object object).
Attribute | Type | Default value | Required | Description |
id | number | - | Yes | Arc ID |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
The method is used via MapContext.removeCustomLayer(Object object).
Attribute | Type | Default value | Required | Description |
layerId | string | - | Yes | ID of personalized layer. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via MapContext.removeGroundOverlay(Object object).
Attribute | Type | Default value | Required | Description |
id | String | - | Yes | ID of image layer |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via MapContext.removeMarkers(Object object).
Attribute | Type | Default value | Required | Description |
markerIds | array | - | Yes | Collection of marker IDs. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via MapContext.setBoundary(Object object).
Attribute | Type | Default value | Required | Description |
southwest | Object | - | Yes | Southwest corner's longitude and latitude |
northeast | Object | - | Yes | Northeast corner's longitude and latitude |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
This method is used via MapContext.setCenterOffset(Object object).
Attribute | Type | Default value | Required | Description |
offset | Array.<number> | - | Yes | Offset value, a two-element array. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via MapContext.setLocMarkerIcon(Object object).
Attribute | Type | Default value | Required | Description |
iconPath | string | - | No | Image path, supporting network paths, local paths, and code package paths. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
The method is used via MapContext.toScreenLocation(Object object).
Attribute | Type | Default value | Required | Description |
latitude | Number | - | Yes | Latitude |
longitude | Number | - | Yes | Longitude |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
x | number | X-coordinate value. |
y | number | Y-coordinate value. |
The method is used via MapContext.translateMarker(Object object).
Attribute | Type | Default value | Required | Description |
markerId | number | - | Yes | Specify a marker. |
destination | object | - | Yes | Specify the target point for the marker to move to. |
animationEnd | function | - | No | Animation completion callback function |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
This method is used via MapContext.updateGroundOverlay(Object object).
Attribute | Type | Default value | Required | Description |
id | String | - | Yes | ID of image layer |
src | String | - | Yes | Image path, supporting network images, temporary paths, and code package paths. |
bounds | Object | - | Yes | Longitude and latitude range covered by the image |
visible | Boolean | true | No | Visible or not |
zIndex | Number | 1 | No | Layer Rendering Sequence |
opacity | Number | 1 | No | Layer Transparency |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Structure attributes | Type | Default value | Required | Description |
southwest | Object | - | Yes | Southwest corner's longitude and latitude |
northeast | Object | - | Yes | Northeast corner's longitude and latitude |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
Structure attributes | Type | Default value | Required | Description |
longitude | number | - | Yes | Longitude |
latitude | number | - | Yes | Latitude |
Was this page helpful?