You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to label several overlapping polygons, but only the label of the biggest one is shown. However when I tested with some simulated data the labels were shown correctly. I compared the data in two cases carefully but cannot find the difference caused the problem.
Here is a minimal example of simulated overlapping polygons:
Turned out that if I change the polygons order in polygons slot, put the bigger one at first will solve the problem. I also tried to change plotOrder in SpatialPolygonsDataFrame, but that doesn't work.
It seemed that leaflet just register area under polygons in order of polygons slot (and not observing plotOrder field in SpatialPolygonsDataFrame), so the bigger polygons will override smaller ones, thus we need to put bigger one at first.
The label is also just a vector by order, so there will be mismatch if data slot in SpatialPolygonsDataFrame are in different order of polygons, even they are matched by rowname and polygon ID.
With more complex user cases, polygons can have intersections, changing order will not solve the problem for the intersection. I'm not sure if there is a better solution here, since it should not be a requirement that polygons in specific order. I used to import same data into Carto.com and the label can be added properly.
I need to label several overlapping polygons, but only the label of the biggest one is shown. However when I tested with some simulated data the labels were shown correctly. I compared the data in two cases carefully but cannot find the difference caused the problem.
Here is a minimal example of simulated overlapping polygons:
It's working properly:
However it didn't work with my data.
Gabs.zip
You can drag the zip into this site and use the
i
button to see it's correctly labeledThe data in both case are
SpatialPolygonsDataFrame
, the data slot have proper polygon names.The text was updated successfully, but these errors were encountered: