I have a map application where:

  1. I load polygons as GeoJSON objects
  2. I draw all polygons in a single layer
  3. I highlight a polygon on mouse hover

What I need to do is the following: on mouse hover, I need to highlight multiple polygons (I get the list of polygons somehow - irrelevant -). I have the IDs of all the polygons I need to highlight, but I can't see how can I access them though the API.

  • 1
    this might be useful leafletjs.com/examples/choropleth.html
    – poshan
    Jun 24, 2014 at 3:57
  • I already used this as a basis. What I need now is to control the visual appearance of each polygon programmatically ... calling them by their IDs
    – firas
    Jun 25, 2014 at 1:08

1 Answer 1


You would have to store polygon IDs in onEachFeature(feature, layer) handler (e.g. layer._polygonId = feature.id), so later you can iterate over layers (e.g. jsonLayer.eachLayer(function(layer) { setHighlighted(layer, doesRelate(layer._polygonId, selectedId)); });.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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