mapcontext.initmarkercluster(object object)
基础库 或更高版本; 若版本较低,建议采取 兼容处理 。
支付宝客户端: 支付宝客户端 10.2.20 或更高版本支持。
主体: 企业支付宝小程序 、 个人支付宝小程序
初始化点聚合的配置,未调用时采用默认配置。
未调用时采用默认配置要设置 marker 的 clusterenabled 属性,指定参与聚合的 marker 对象。
object object
查看示例
属性 | 类型 | 默认值 | 必填 | 描述 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
clusterranges | array | - | 是 | 聚合算法可聚合的缩放级别。 |
||||||||||
|
||||||||||||||
clusterdistance | number | 50 | 否 | 聚合算法的可聚合距离,即距离小于该值的点会聚合至一起,以像素为单位。 |
||||||||||
referenceparam | string | - | 否 | 将 marker 聚合后的数量应用到聚合样式中,需配合 iconlayout 使用。 |
||||||||||
iconlayout | object | - | 是 | 使用“map 高级定制渲染”进行聚合点样式自定义 |
||||||||||
success | function | - | 否 | 调用成功的回调函数。 |
||||||||||
fail | function | - | 否 | 调用失败的回调函数。 |
||||||||||
complete | function | - | 否 | 调用结束的回调函数(调用成功、失败都会执行)。 |
success 回调函数
参数
object res
属性 | 类型 | 描述 |
---|---|---|
success | boolean | 是否成功调用 |
fail 回调函数
参数
object err
属性 | 类型 | 描述 |
---|---|---|
error | 错误码 |
|
errormessage | 错误信息 |
fail 回调的参数为 object,error
属性为错误码,errormessage
属性为错误消息。
错误码 | 错误消息 | 凯发app官方网站的解决方案 |
---|---|---|
2 | 接口参数无效 |
请按照要求传入参 |
mapcontext.smoothdrawpolyline js 代码
const markers = [
{
"height": 74,
"longitude": 120.1317034697479,
"id": 10,
"latitude": 30.219073976739733,
"clusterenabled": true,
"iconlayout":{
src:"/layout/sport.xml",
params:{
name:"聚合点1",
logo:"https://gw.alipayobjects.com/xxx.png"
}
}
},
{
"height": 74,
"longitude": 120.13359192047646,
"id": 11,
"latitude": 30.21748804275829,
"clusterenabled": true,
"iconlayout":{
src:"/layout/sport.xml",
params:{
name:"聚合点2",
logo:"https://gw.alipayobjects.com/xxx.png"
}
}
}];
page({
data: {
mapctx: null,
markers
},
onready() {
this.data.mapctx = my.createmapcontext('map');
},
initmarkercluster(){
this.mapctx.initmarkercluster({
clusterranges:[{
from: 5,
to: 25
}],
clusterdistance: 100,
referenceparam: "name", // dsl关联替换参数名称
iconlayout: {
params: {
logo: "https://xxx.png",
},
src: '/layout/sport.xml',
},
success: (e)=>{
console.log("initmarkercluster success:", e)
},
fail:(e)=>{
console.log("initmarkercluster fail:", e)
}
})
}
});