leaflet-panel-layers
leaflet-panel-layers copied to clipboard
Enhance 'buildItem' to be layer specific instead of just group specific
I'd like to use the 'buildItem' function for just one layer in the layer control, or have different buildItem functions for each layer.
For those developers wanting to experiment with this type of functionality, edit the custom-item.html example:
{
name: "Parking",
background: 'images/icons/parking.png',
layer: L.geoJson(Parking, {pointToLayer: featureToMarker }),
buildItem: function(item) {
var points = item.layer.getLayers ? item.layer.getLayers().length : 0,
label = points ? ' ('+points+')' : '',
size = Math.min(18,Math.max(9,points))+'px',
node = L.DomUtil.create('span','');
node.innerHTML = label;
if(points)
node.style.fontSize = size;
if(item.background) {
node.style.background = "url('"+item.background+"') center left no-repeat";
node.style.paddingLeft = '24px';
}
return node;
}
}
],
//options
{ buildItem: function(item) {
var node;
if (item.buildItem) {
node = item.buildItem.call(this, item);
} else {
node = L.DomUtil.create('span','');
}
return node;
}
}
) );
Note the icon and number of points is shown only for the Parking layer: