Ok, so you must be using the HTML marker layer then which is an extension module, as that would be the only way to create a cluster using an HTML marker. HTML markers don't normally connect to data sources and thus have no references to them. The HTML marker layer wraps a hidden bubble layer that's connected to a data source, and then creates/removes HTML markers as the map moves. One solution to your problem would be to create a different event handler for each data source you have. Here is a simple example that does this:
//A function that wraps a data source and returns an event handler function.
function markerClicked(source) {
return function(e) {
var marker = e.target;
if (marker.properties.cluster) {
//Get the cluster expansion zoom level. This is the zoom level at which the cluster starts to break apart.
source.getClusterExpansionZoom(marker.properties.cluster_id).then(function (zoom) {
//Update the map camera to be centered over the cluster.
map.setCamera({
center: marker.getOptions().position,
zoom: zoom,
type: 'ease',
duration: 200
});
});
} else {
//Code for single marker location.
}
};
}
var markerLayer = new atlas.layer.HtmlMarkerLayer(datasource, null, {
markerCallback: function (id, position, properties) {
//Your logic for creating markers.
}
});
//Add click event, wrap data source with handler.
map.events.add('click', markerLayer, markerClicked(datasource));