Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marker cluster sumatory of markers label #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
3 changes: 2 additions & 1 deletion www/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,8 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
'idxCount': positionList.length + 1,
'maxZoomLevel': Math.min(markerClusterOptions.maxZoomLevel || 15, 18),
'debug': markerClusterOptions.debug === true,
'boundsDraw': common.defaultTrueOption(markerClusterOptions.boundsDraw)
'boundsDraw': common.defaultTrueOption(markerClusterOptions.boundsDraw),
'sumLabels': markerClusterOptions.sumLabels
}, exec);
var markerClusterId = markerCluster.getId();
self.OVERLAYS[markerClusterId] = markerCluster;
Expand Down
40 changes: 37 additions & 3 deletions www/MarkerCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ var MarkerCluster = function (map, markerClusterOptions, _exec) {
value: markerClusterOptions.boundsDraw === true,
writable: false
});
Object.defineProperty(self, 'sumLabels', {
value: markerClusterOptions.sumLabels,
writable: false
});

if (self.boundsDraw) {
self.map.addPolygon({
Expand Down Expand Up @@ -955,13 +959,25 @@ Object.defineProperty(MarkerCluster.prototype, '_redraw', {
}

unionedMarkers.forEach(function (cluster) {

var countCluster = 0;
if (self.sumLabels) {
cluster._markerArray.forEach(function (marker) {
var data = marker.get('data');
if (data) {
countCluster = countCluster + self.getClusterLabelData(self, data, self.sumLabels)
} else {
countCluster = countCluster + 1;
}
});
} else {
countCluster = cluster.getItemLength();
}
var icon = self.getClusterIcon(cluster),
clusterOpts = {
'count': cluster.getItemLength(),
'count': countCluster,
'position': cluster.getBounds().getCenter(),
'__pgmId': cluster.getId()
};
};

if (self.debug) {
clusterOpts.geocell = cluster.geocell;
Expand Down Expand Up @@ -1099,6 +1115,24 @@ Object.defineProperty(MarkerCluster.prototype, '_redraw', {
}
});

MarkerCluster.prototype.getClusterLabelData = function (self, data, key) {
var self = self;
var index = key.indexOf(".");
var firstPart = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cambiar la manera de acceder por esta manera, con un comentario a este enlace:

https://stackoverflow.com/questions/8051975/access-object-child-properties-using-a-dot-notation-string

var secondPart = null;
if (index != -1) {
firstPart = key.substr(0, index)
secondPart = key.substr(index + 1)
} else {
firstPart = key.substr(index + 1)
}
if (secondPart) {
return self.getClusterLabelData(self, data[firstPart], secondPart)
} else {
return data[firstPart];
}
}

MarkerCluster.prototype.getClusterIcon = function (cluster) {
var self = this,
hit,
Expand Down