0

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.

twg_
  • 995
  • 2
  • 7
  • 15
  • see if this helps http://stackoverflow.com/questions/13316925/simple-label-on-a-leaflet-geojson-polygon – muzaffar May 04 '16 at 08:01
  • I've tried that. I had to modify it a little due to me reading my JSON into a variable so I didn't have to keep making calls out to the file. Still doesn't put a label on the map. – twg_ May 04 '16 at 15:16
  • Possible duplicate of [Simple label on a leaflet (geojson) polygon](https://stackoverflow.com/questions/13316925/simple-label-on-a-leaflet-geojson-polygon) – Borealis May 29 '17 at 14:48

0 Answers0