Search code examples
leafletcartodb

Widget to zoom an centre on polygon in carto db or leaflet


I am looking for a widget or a script example which generates a clickable list of all polygons in a layer - when a polygon in the legend is clicked, the map is panned/zoomed to that polygon.


Solution

  • Hard to say exactly what you are looking for with the little details provided in your question, but you might be interested in Leaflet.CountrySelect plugin:

    Control with menu of all countries, and an event listener that returns the selected country as a GeoJSON feature (demo)

    (although it is about "countries", it just returns whatever JavaScript object you have passed to the countries option)

    You can see how it is used in the demo source page, and it is also explained on the plugin home page.