I'm trying to add labels to polygons on my map.
Currently I'm reading in all of my JSON data into a variable and then when a user clicks a checkbox, all the polygons are loaded. I'm just not sure how to add the label to the polygon.
var construction = L.geoJson.ajax('inc/my-data.json', {
style: function(feature){
return constructionOptions;
},filter: function(feature, layer){
return feature.properties.show_on_map;
},onEachFeature: function(feature, layer){
$('ul').append('<li><a href="#">' + feature.properties.name + '</a></li>');
}
});
// Watches checkbox event
$('ul li input').on('change', function(){
if(this.checked)
{
if(this.value === 'construction')
{
construction.addTo(map);
}
}else{
if(this.value === 'construction')
{
deletePolygon(construction);
}
}
});
I only want these labels to show when the 'construction' item is checked.