Polygon labels with Leaflet

654 views
Skip to first unread message

Juventus Ventuno

unread,
Jan 3, 2015, 7:41:56 PM1/3/15
to leafl...@googlegroups.com
I am using the Bootleaf Template and have presented 5 polygons from GeoJSON successfully.
In trying to add simple labels from 'NAME' field to center of each polygon using L.circleMarker(layer.getBounds().getCenter()); I get "bindLabel is not a function" error.

Is there a functional way to do this?

Code below:

var districts = L.geoJson(null, {
  style: function (feature) {
    return {
       color: "white",
       fill: true,
       weight: 2,
      opacity: 0.8
    };
  },
 

onEachFeature: function (feature, layer) {
    layer.on('mouseover', function () {
      this.setStyle({
        'fillColor': '#0000ff'
      });
    });
    layer.on('mouseout', function () {
      this.setStyle({
        'fillColor': '#ff0000'
      });
    });
    layer.on('click', function () {
    window.location = feature.properties.URL;
    });

var circleMarker = L.circleMarker(layer.getBounds().getCenter());
// e.g. using Leaflet.label plugin
circleMarker.bindLabel(feature.properties['NAME'], { noHide: true })
    .circleMarker.addTo(map);
}

});

$.getJSON("data/districts.geojson", function (data) {
  districts.addData(data);
});

Luca Volpin

unread,
Jul 12, 2016, 5:11:13 AM7/12/16
to Leaflet
ciao, ho il tuo stesso problema con le etichette da inserire in bootleaf, hai risolto? se si mi puoi dare qualche suggerimento? grazie
Reply all
Reply to author
Forward
0 new messages