Skip to content

Commit

Permalink
json-configurable cluster icon (see #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Sep 17, 2015
1 parent 7827f44 commit 7735432
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion js/wq/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ map.addOverlayType('geojson', function(layerconf) {
if (layerconf.cluster && L.MarkerClusterGroup) {
var options = {};
if (layerconf.clusterIcon) {
options.iconCreateFunction = layerconf.clusterIcon;
options.iconCreateFunction = _makeCluster(layerconf.clusterIcon);
}
overlay = new L.MarkerClusterGroup(options);
} else {
Expand Down Expand Up @@ -623,6 +623,35 @@ function _makeMarker(icon) {
};
}

function _makeCluster(clusterIcon) {
return function clusterDiv(cluster) {
var cls;
var context = {
'count': cluster.getChildCount()
};
if (context.count >= 100) {
context.large = true;
} else if (context.count >= 10) {
context.medium = true;
} else {
context.small = true;
}
if (typeof clusterIcon == 'function') {
cls = clusterIcon(context);
} else if (clusterIcon.indexOf('{{') > -1) {
cls = tmpl.render(clusterIcon, context);
} else {
cls = clusterIcon;
}
var html = tmpl.render('<div><span>{{count}}</span></div>', context);
return new L.DivIcon({
html: html,
className: 'marker-cluster ' + cls,
iconSize: new L.Point(40, 40)
});
};
}

// Load map configuration for a given page
function _getConf(page, mode) {
var conf = map.config.maps[page];
Expand Down

0 comments on commit 7735432

Please sign in to comment.