You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
export default function set_cluster(map_obj, markers = [], clusterEvent = [], icon, district, circle) { |
|
if (typeof map_obj === 'undefined') { |
|
return; |
|
} |
|
map_obj.plugin(['AMap.MarkerClusterer'], function () { |
|
if (map_obj.cluster) { |
|
map_obj.cluster.clearMarkers(); |
|
} |
|
const styles = [{ url: icon, size: { width: 42, height: 42 } }]; |
|
const sts = styles.map((item) => { |
|
let obj = { |
|
url: item.url, |
|
size: new AMap.Size(42, 42), |
|
}; |
|
obj.offset = new AMap.Pixel(-10, -21); |
|
obj.textColor = '#fff'; |
|
return obj; |
|
}); |
|
let cluster = new AMap.MarkerClusterer(map_obj, markers, { |
|
gridSize: 80, |
|
styles: sts, |
|
}); |
|
clusterEvent.forEach(function (event) { |
|
cluster.on(event['type'], function (currentObj) { |
|
event['eventHandle'](this, currentObj); |
|
}); |
|
}); |
|
//聚合打点 |
|
cluster.addMarkers(markers); |
|
map_obj.cluster = cluster; |
|
// 坐标点自适应 |
|
if (!district || !circle) { |
|
map_obj.setFitView(markers); |
|
} |
|
// 清除坐标点 |
|
map_obj.removeMarkers = function () { |
|
cluster.clearMarkers(); |
|
}; |
|
}); |
|
}
|
|
|