[GIS] How to make polygons clickable in Leaflet.js / folium

leafletpandaspython

I'm trying to create a clickable leaflet.js map using folium and Python.

After a previous query – answered here Geopandas/folium map not displaying – I've added the polygons.

But I'm getting a little bit lost in the documentation on what to add to the output javascript to create a pop up for each polygon using the dataframe.

Can anyone give me a steer in the right direction, please?

Best Answer

Didn't have time to take a look before but following Leaflet documentation http://leafletjs.com/reference.html#geojson, you just have to change GeoJSON layer declaration from:

gJson_layer_1 = L.geoJson(gjson_1, {style: style_1}).addTo(map)

to :

gJson_layer_1 = L.geoJson(gjson_1, {
  style: style_1,
  onEachFeature: function (feature, layer) {
    layer.bindPopup(feature.properties.PCON13NM);
  }
}).addTo(map)
Related Question