In a Leaflet GeoJSON polygon layer, I want a popup information box, showing attributes of each of the polygon properties. So the final output should show the Country Name, Area, Population etc properties accessed from the GeoJSON layer of the particular polygon; something like the image.

GeoJSON layer popup example

For this reason what should I write inside Popup?

gj = folium.GeoJson(open("country.geojson",encoding = "utf-8-sig").read())
popup = folium.Popup('Country name: ')
  • Maybe this can get you going in the right direction: stackoverflow.com/questions/38171687/… – TomazicM Apr 15 '20 at 8:59
  • I tried to write a code following that post as you directed but all I get is the message "'GeoJson' object is not subscriptable" – Mehmud Apr 15 '20 at 9:15
  • 1
    Since I have 0 experience with Folium and no environment to try it, I'm afraid I can't help you here. – TomazicM Apr 15 '20 at 9:42

In Leaflet you can use the option onEachFeature from the L.GeoJSON class to declare a function for each layer in the GeoJSON.

Here is a example on JsFiddle: https://jsfiddle.net/guihig/5j0n7wm8/9/

Note that I used a previous made GeoJSON dataset from this link: https://github.com/datasets/geo-countries/blob/master/data/countries.geojson

  • This syntax does not work in Folium. – TomazicM Apr 15 '20 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.