tencent cloud

Last updated: 2025-11-13 15:14:07
Map
Last updated: 2025-11-13 15:14:07

createMapContext

This API is called using wx.createMapContext(string mapId, Object this).
Feature description: Creates a map context object MapContext .
Parameter and description:
string mapId: The ID of the map component.
Object this: the current component instance (this), used when inside a custom component to operate the map component within it.
Return value:MapContext.

MapContext

Note:
Unless otherwise specified, the methods of MapContext are supported by the following map providers by default:
System Maps (iOS only): Supported.
Google Maps (Android, IDE): Supported.
Petal Maps (Android only): Supported.
Tencent Maps: Supported.
Baidu Maps: Supported.
Amap: Supported.
A MapContext instance can be obtained via  wx.createMapContext .
The MapContext is bound to a  map  component by its ID, allowing you to control that  map  component.
Example:
<!-- 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.js
Page({
onReady: function (e) {
// Get the map context using wx.createMapContext
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,
}]
})
}
})

.addArc

This method is called using MapContext.addArc(Object object).
Note:
iOS, Android, and IDE: Not supported.
Feature description: Adds an arc to the map. Either a pass-through point or an angle must be set. The pass-through point must lie within the valid coordinate range between the start and end points; otherwise, the arc cannot be generated correctly. When an angle is set, it takes precedence. The angle is defined as the counterclockwise rotation from the tangent line at the start point to the line connecting the start and end points.
Parameter and description: Object object
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).
Structure of start
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.
Structure of end:
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.
Structure of pass:
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.

.addCustomLayer

This method is called using MapContext.addCustomLayer(Object object).
Note:
iOS, Android, and IDE: Not supported.
Feature description: Adds a custom layer. For details about layer creation, see Reference.
Parameter and description: Object object
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).

.addGroundOverlay

This method is called using MapContext.addGroundOverlay(Object object).
Note:
IDE: Supported. Android and iOS: Not supported.
Feature description: Creates a custom image layer. The image will scale as the map zooms.
Parameter and description: Object object
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).
Structure of bounds
Property
Type
Default value
‍Required
Description
southwest
Object
-
True
Southwest corner latitude and longitude.
northeast
Object
-
True
Northeast corner latitude and longitude.
Structure of southwest
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.
Structure of northeast
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.

.addMarkers

This method is called using MapContext.addMarkers(Object object).
Feature description: Adds markers.
Parameter and description: Object object.
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).

.eraseLines

This method is called using MapContext.eraseLines(Object object).
Feature description: Erases or grays out lines that have been added to the map.
Parameter and description: Object object
Property
Type
Default value
‍Required
Description
lines
Array.<Object>
-
True
An array of lines to erase. For details, see polyline.
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).
Structure of lines
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.
Structure of point
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.

.fromScreenLocation

This method is called using MapContext.fromScreenLocation(Object object).
Feature description: Gets the latitude and longitude corresponding to a point on the screen, with the coordinate origin at the top-left corner of the map.
Parameter and description: Object object
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).
object.success callback function parameter: Object res.
Property
Type
Description
latitude
number
The latitude.
longitude
number
The longitude.

.getCenterLocation

This method is called using MapContext.getCenterLocation(Object object).
Feature description: Gets the latitude and longitude of the current map center. The returned coordinates use the GCJ-02 coordinate system and can be used with  wx.openLocation().
Parameter and description: Object object
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).
object.success callback function parameter: Object res
Property
Type
Description
longitude
number
The longitude.
latitude
number
The latitude.

.getRegion

This method is called using MapContext.getRegion(Object object).
Feature description: Gets the current visible region of the map.
Parameter and description: Object object
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).
object.success callback function parameter: Object res
Property
Type
Description
southwest
object
Southwest corner latitude and longitude.
northeast
object
Northeast corner latitude and longitude.
Structure of southwest
Property
Type
Description
longitude
number
The longitude.
latitude
number
The latitude.
Structure of northeast
Property
Type
Description
longitude
number
The longitude.
latitude
number
The latitude.

.getRotate

Note:
Not supported on iOS.
This method is called using MapContext.getRotate(Object object).
Feature description: Gets the current rotation angle of the map.
Parameter and description: Object object
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).
object.success callback function parameter: Object res
Property
Type
Description
rotate
number
Rotation angle.

.getScale

This method is called using MapContext.getScale(Object object).
Feature description: Gets the current zoom scale level of the map.
Parameter and description: Object object
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).
object.success callback function parameter: Object res
Property
Type
Description
scale
number
Zoom scale level.

.getSkew

Note:
Not supported on iOS.
This method is called using MapContext.getSkew(Object object).
Feature description: Gets the current tilt angle of the map.
Parameter and description: Object object
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).
object.success callback function parameter: Object res
Property
Type
Description
skew
number
Tilt angle.

.includePoints

Note:
Not supported on iOS.
This method is called using MapContext.includePoints(Object object).
Feature description: Zooms the viewport to display all specified latitude and longitude points.
Parameter and description: Object object
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).
Structure of points
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.

.initMarkerCluster

This method is called using MapContext.initMarkerCluster(Object object).
Feature description: Initializes the configuration for marker clustering. If not called, default configurations will be applied.
Parameter and description: Object object
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).

.moveAlong

This method is called using MapContext.moveAlong(Object object).
Feature description: Moves a 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.
Parameter and description: Object object
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).

.moveToLocation

This method is called using MapContext.moveToLocation(Object object).
Feature description: Moves the map center to the current location point. Requires the map component's show-location to be set to true.
Parameter and description: Object object
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).

.on

This method is called using MapContext.on(string event, function callback).
Feature description: Listens for map events.
Parameter 1: visualLayerEvent, a unified callback handler for the visual layer (visualLayer), supported starting from version 1.5.16.
Parameter
Type
Description
layerId
String
Layer ID.
eventType
String
Event type.
eventInfo
String
Event information.
Parameter 2: markerClusterCreate, triggered when zooming or dragging causes new marker clusters to be created, and only returns information about the newly created marker clusters.
Parameter
Type
Description
clusters
Array<ClusterInfo>
Data for the newly created clusters.
Parameter 3: markerClusterClick, triggered when a cluster is tapped.
Parameter
Type
Description
cluster
ClusterInfo
The tapped cluster.
ClusterInfo structure
Parameter
Type
Description
clusterId
Number
Cluster ID.
center
LatLng
Coordinates of the cluster.
markerIds
Array<Number>
Array of marker IDs within the cluster.
Parameter 4: The parameter event is the name of the event, with a type of string. The parameter callback is the event’s callback function, with a type of function.
Valid values for event: markerClusterCreate, markerClusterClick, visualLayerEvent.
Example
MapContext.on('visualLayerEvent', (res) => {})
MapContext.on('markerClusterCreate', (res) => {})
MapContext.on('markerClusterClick', (res) => {})

.openMapApp

This method is called using MapContext.openMapApp(Object object).
Feature description: Opens a map app for navigation selection.
Parameter and description: Object object
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).

.removeArc

This method is called using MapContext.removeArc(Object object).
Note:
iOS, Android, and IDE: Not supported.
Feature description: Removes an arc.
Parameter and description: Object object
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).

.removeCustomLayer

This method is called using MapContext.removeCustomLayer(Object object).
Note:
iOS, Android, and IDE: Not supported.
Feature description: Removes a custom layer.
Parameter and description: Object object
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).

.removeGroundOverlay

This method is called using MapContext.removeGroundOverlay(Object object).
Note:
IDE: Supported. Android and iOS: Not supported.
Feature description: Removes a custom image layer.
Parameter and description: Object object
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).

.removeMarkers

This method is called using MapContext.removeMarkers(Object object).
Feature description: Removes markers.
Parameter and description: Object object
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).

.setBoundary

This method is called using MapContext.setBoundary(Object object).
Feature description: Sets the display boundary of the map. This API also limits the map’s minimum zoom level to an integer value.
Parameter and description: Object object
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).
Structure of southwest
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.
Structure of northeast
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.

.setCenterOffset

This method is called using MapContext.setCenterOffset(Object object).
Feature description: Sets the map’s center point offset, with increases moving backward and downward. The screen ratio range is 0.25 to 0.75, and the default offset is [0.5, 0.5].
Parameter and description: Object object
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).

.setLocMarkerIcon

This method is called using MapContext.setLocMarkerIcon(Object object).
Feature description: Sets the icon for the location marker. Supports network paths, local paths, and code package paths.
Parameter and description: Object object
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).

.toScreenLocation

This method is called using MapContext.toScreenLocation(Object object).
Feature description: Gets the screen coordinates corresponding to a given latitude and longitude, with the coordinate origin at the top-left corner of the map.
Parameter and description: Object object
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).
object.success callback function parameter: Object res
Property
Type
Description
x
number
The x coordinate value.
y
number
The y coordinate value.

.translateMarker

This method is called using MapContext.translateMarker(Object object).
Feature description: Translates a marker. Animation is supported on iOS and IDE, but not currently on Android.
Parameter and description: Object object
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).
Structure of destination
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.

.updateGroundOverlay

This method is called using MapContext.updateGroundOverlay(Object object).
Note:
IDE: Supported. Android and iOS: Not supported.
Feature description: Updates a custom image layer.
Parameter and description: Object object
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).
Structure of bounds
Property
Type
Default value
‍Required
Description
southwest
Object
-
True
Southwest corner latitude and longitude.
northeast
Object
-
True
Northeast corner latitude and longitude.
Structure of southwest
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.
Structure of northeast
Property
Type
Default value
‍Required
Description
longitude
number
-
True
The longitude.
latitude
number
-
True
The latitude.

.downloadOfflineMap

This method is called using MapContext.downloadOfflineMap(Object object).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Downloads the offline map for a specified region.
Parameter and description: Object object
Property
Type
Default value
‍Required
Description
region
string
-
True
Regional identifier, e.g., Shanghai. For details, see:region.json
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).
object.success callback function parameter
Property
Type
Description
taskId
string
Task ID.

.cancelDownload

This method is called using MapContext.cancelDownload(Object object).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Cancels the specified offline map download task.
Parameter and description: Object object
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).

.getOfflineMapList

This method is called using MapContext.getOfflineMapList(Object object).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Queries the list of locally downloaded offline map packages.
Parameter and description: Object object
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).
object.success callback function parameter: Array.<Object> res
Property
Type
Description
id
string
Unique ID of the offline package.
region
string
Region name.
size
number
Package size (in bytes).

.deleteOfflineMap

This method is called using MapContext.deleteOfflineMap(Object object).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Deletes an offline package.
Parameter and description: Object object
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).
object.success callback function parameter: Array.<Object> res
Property
Type
Description
id
string
Unique ID of the offline package.
region
string
Region name.
size
number
Package size (in bytes).

.onDownloadComplete

This method is called using MapContext.onDownloadComplete(Function listener).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Listens for the completion of offline map package downloads.
Parameter and description: Function listener
Function listener callback function parameter: Object res
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).

.offDownloadComplete

This method is called using MapContext.offDownloadComplete(Function listener).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Removes the listener for offline package download completion.

.onDownloadError

This method is called using MapContext.onDownloadError(Function listener).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Listens for offline map package download failures.
Parameter and description: Function listener
Function listener callback function parameter: Object res
Property
Type
Description
taskId
string
Task ID.
region
string
Region name.
error
object
Failure reason.

.offDownloadError

This method is called using MapContext.offDownloadError(Function listener).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Removes the listener for offline map package download failures.

.addTileLayer

This method is called using MapContext.addTileLayer(Object object).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Adds a custom tile layer.
Parameter and description: Object object
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).
object.success callback function parameter: Object object
Property
Type
Description
layerId
string
ID of the custom tile layer.
sourceUrlFormat structure description
URL example:
https://api.hkmapservice.gov.hk/ags/map/basemap/WGS84/tile/{z}/{y}/{x}
App sandbox path examples:
Android internal storage: /data/data/ {package name} /files/tiles/ {z} - {y} - {x}
Android external storage: /sdcard/Android/data/ {package name} /files/tiles/ {z} - {y} - {x}
IOS: /var/mobile/Containers/Data/Application/0D7351C7-351B-4A85-8DFB-412A61D797A8/Library/Caches/{z}-{y}-{x}
Mini program sandbox path example:
wxfile://usr/custom/{z}-{y}-{x}

Note: {z}/{y}/{x} and {z}-{y}-{x} are both formal parameters. Other formats like {arg1}{arg2}{arg3} are also possible. The curly braces "{" and "}" are required as part of the template.
Parameter
Description
x
The longitude.
y
The latitude.
z
Zoom level.
Example:
// createLayer
createLayer: 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);
}
})
}

// downloadAndCreateLayer
downloadAndCreateLayer: 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);
}
})
},

.removeTileLayer

This method is called using MapContext.removeTileLayer(Object object).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Removes a custom tile layer.
Parameter and description: Object object
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).

.setTileLayerVisibility

This method is called using MapContext.setTileLayerVisibility(Object object).
Note:
IDE: Not supported. Android and iOS: Supported.
Only supported in Tencent Maps.
Feature description: Controls the visibility (show/hide) of a custom tile layer.
Parameter and description: Object object
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).


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback