<!-- map.wxml --><map id="myMap" show-location /><button type="primary" bindtap="getCenterLocation">Get the location</button><button type="primary" bindtap="moveToLocation">Move to the location</button><button type="primary" bindtap="translateMarker">Move the marker</button><button type="primary" bindtap="includePoints">Zoom to show all latitude and longitude points</button>
// map.jsPage({onReady: function (e) {// Get the map context using wx.createMapContextthis.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,}]})}})
Property | Type | Default value | Required | Description |
id | number | - | True | Arc ID. |
start | Object | - | True | Start point. |
end | Object | - | True | End point. |
pass | Object | - | False | Pass-through point. |
angle | number | 0 | False | Angle in degrees. |
width | number | 5 | False | Line width. |
color | number | #000000 | False | Line color. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
layerId | string | - | True | ID of the custom layer. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
id | String | - | True | ID of the image layer. |
src | String | - | True | Image path. Supports network images, temporary paths, and code package paths. |
bounds | Object | - | True | Latitude and longitude range covered by the image. |
visible | Boolean | true | False | Whether visible. |
zIndex | Number | 1 | False | Drawing order of the layer. |
opacity | Number | 1 | False | Opacity of the layer. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
southwest | Object | - | True | Southwest corner latitude and longitude. |
northeast | Object | - | True | Northeast corner latitude and longitude. |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
markers | array | - | True | Same as the marker property passed to the map component. |
clear | boolean | false | False | Whether to clear all markers on the map first. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
lines | Array.<Object> | - | True | |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
id | number | - | True | Line ID. |
index | number | - | True | A specific segment of the line, where the starting point of the line segment has an index of 0. |
point | Object | - | True | A point within a specified line segment. |
clear | boolean | true | False | True for erase, false for gray out. |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
x | number | - | True | The x coordinate value. |
y | number | - | True | The y coordinate value. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
latitude | number | The latitude. |
longitude | number | The longitude. |
Property | Type | Default value | Required | Description |
iconPath | string | - | False | Icon path. Supports network paths, local paths, and code package paths. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
longitude | number | The longitude. |
latitude | number | The latitude. |
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
southwest | object | Southwest corner latitude and longitude. |
northeast | object | Northeast corner latitude and longitude. |
Property | Type | Description |
longitude | number | The longitude. |
latitude | number | The latitude. |
Property | Type | Description |
longitude | number | The longitude. |
latitude | number | The latitude. |
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
rotate | number | Rotation angle. |
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
scale | number | Zoom scale level. |
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
skew | number | Tilt angle. |
Property | Type | Default value | Required | Description |
points | array.<Object> | - | True | List of coordinate points to be displayed within the visible region. |
padding | array.<number> | - | False | The distance (in pixels) from the edges of the rectangle formed by coordinate points to the edges of the map. The format is [top, right, bottom, left]. On Android, only the first item in the array is recognized, applying the same padding to all sides. The padding parameter is temporarily not supported in IDE. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
enableDefaultStyle | boolean | true | False | Enables the default clustering style. |
zoomOnClick | boolean | true | False | Whether to trigger cluster splitting when a clustered marker is tapped. |
gridSize | number | 60 | False | The clustering algorithm’s aggregation distance, meaning points closer than this value will cluster together; measured in pixels. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
marker along a specified path, typically used for playback of routes or tracks. A callback event is triggered when the animation is complete. If the animation is in progress and the moveAlong method is called again on the same marker , the previous animation will be interrupted.Property | Type | Default value | Required | Description |
markerId | number | - | True | The specified marker. |
path | array | - | True | Array of coordinates for the movement path, each point formatted as {longitude, latitude}. |
autoRotate | boolean | true | False | Automatically adjusts the marker's rotation angle based on the path direction. |
duration | number | - | True | Duration of the smooth movement. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
longitude | number | - | False | The longitude. |
latitude | number | - | False | The latitude. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Parameter | Type | Description |
layerId | String | Layer ID. |
eventType | String | Event type. |
eventInfo | String | Event information. |
Parameter | Type | Description |
clusters | Array<ClusterInfo> | Data for the newly created clusters. |
Parameter | Type | Description |
cluster | ClusterInfo | The tapped cluster. |
Parameter | Type | Description |
clusterId | Number | Cluster ID. |
center | LatLng | Coordinates of the cluster. |
markerIds | Array<Number> | Array of marker IDs within the cluster. |
MapContext.on('visualLayerEvent', (res) => {})MapContext.on('markerClusterCreate', (res) => {})MapContext.on('markerClusterClick', (res) => {})
Property | Type | Default value | Required | Description |
longitude | number | - | True | Destination longitude. |
latitude | number | - | True | Destination latitude. |
destination | string | - | True | Destination name. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
id | number | - | True | Arc ID. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
layerId | string | - | True | ID of the custom layer. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
id | String | - | True | ID of the image layer. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
markerIds | array | - | True | The array of marker IDs. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
southwest | Object | - | True | Southwest corner latitude and longitude. |
northeast | Object | - | True | Northeast corner latitude and longitude. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
offset | Array.<number> | - | True | Offset value, an array of two numbers. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
iconPath | string | - | False | Icon path. Supports network paths, local paths, and code package paths. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
latitude | Number | - | True | The latitude. |
longitude | Number | - | True | The longitude. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
x | number | The x coordinate value. |
y | number | The y coordinate value. |
Property | Type | Default value | Required | Description |
markerId | number | - | True | The specified marker. |
destination | object | - | True | The target point to which the marker moves. |
animationEnd | function | - | False | Callback function after the animation ends. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
id | String | - | True | ID of the image layer. |
src | String | - | True | Image path. Supports network images, temporary paths, and code package paths. |
bounds | Object | - | True | Latitude and longitude range covered by the image. |
visible | Boolean | true | False | Whether visible. |
zIndex | Number | 1 | False | Drawing order of the layer. |
opacity | Number | 1 | False | Opacity of the layer. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
southwest | Object | - | True | Southwest corner latitude and longitude. |
northeast | Object | - | True | Northeast corner latitude and longitude. |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
longitude | number | - | True | The longitude. |
latitude | number | - | True | The latitude. |
Property | Type | Default value | Required | Description |
region | string | - | True | |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
taskId | string | Task ID. |
Property | Type | Default value | Required | Description |
taskId | string | - | True | Task ID. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
id | string | Unique ID of the offline package. |
region | string | Region name. |
size | number | Package size (in bytes). |
Property | Type | Default value | Required | Description |
id | string | - | True | ID of the offline package to delete. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
id | string | Unique ID of the offline package. |
region | string | Region name. |
size | number | Package size (in bytes). |
Property | Type | Description |
taskId | string | Task ID. |
region | string | Region name. |
id | string | Unique ID of the offline package. |
size | number | Package size (in bytes). |
Property | Type | Description |
taskId | string | Task ID. |
region | string | Region name. |
error | object | Failure reason. |
Property | Type | Default value | Required | Description |
sourceUrlFormat | string | - | True | Tile data path format (supports URL, app sandbox paths, and mini program sandbox paths). Note: Online paths require configuring the DownloadFile allowlist in the console. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
layerId | string | ID of the custom tile layer. |
Parameter | Description |
x | The longitude. |
y | The latitude. |
z | Zoom level. |
// createLayercreateLayer: function () {const mapContext = wx.createMapContext('customMap');mapContext.addTileLayer({sourceUrlFormat: 'http://x.x.x.x/{z}/{y}/{x}',success: (res) => {console.log('addTileLayer success', res);},fail: (res) => {console.log('addTileLayer fail', res);}})}
// downloadAndCreateLayerdownloadAndCreateLayer: function () {console.log(wx.env.USER_DATA_PATH)wx.downloadFile({url: 'http://x.x.x.x/download',success: (res) => {console.log('downloadFile success', res);const tempFilePath = res.tempFilePath;const targetPath = wx.env.USER_DATA_PATH + '/customFile';console.log('targetPath', targetPath);const systemManager = wx.getFileSystemManager();systemManager.unzip({zipFilePath: tempFilePath,targetPath: targetPath,success: (res) => {console.log('unzip success', res);const sourceUrlFormat = `${targetPath}/{z}/{y}/{x}`;console.log('sourceUrlFormat', sourceUrlFormat);this.mapContext.addTileLayer({sourceUrlFormat,success: (res) => {console.log('addTileLayer success', res);},fail: (res) => {console.log('addTileLayer fail', res);}})}})},onfail: (res) => {console.log('downloadFile fail', res);}})},
Property | Type | Default value | Required | Description |
layerId | string | - | True | ID of the custom tile layer. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
layerId | string | - | True | ID of the custom tile layer. |
visible | boolean | - | True | Whether visible. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Feedback