5

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 '14 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 – FearUs Jun 25 '14 at 1:08
3

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)); });.

1

Check out my fiddle here, I think this is kind of what you're looking for --- http://jsfiddle.net/mkhines/SZk4u/embedded/result/

  • it uses leaflet pip to do some work -- github.com/mapbox/leaflet-pip – megan Jun 25 '14 at 13:31
  • Welcome to SE and thanks for your answer! Comments are really meant for clarification, so if you're commenting on your own answer, you might be better off simply editing to include the additional information. gis.stackexchange.com/tour – GISKid Jun 25 '14 at 13:53

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.