openstreetmap / iD

🆔 The easy-to-use OpenStreetMap editor in JavaScript.
https://www.openstreetmap.org/edit?editor=id
ISC License
3.34k stars 1.2k forks source link

Area label appears outside area for complex shapes #2466

Open andyclegg opened 9 years ago

andyclegg commented 9 years ago

For example, see http://www.openstreetmap.org/edit?editor=id&way=23543197#map=18/57.17726/-2.14126 The label for 'River Don' appears on top of the northernmost soccer field. I am presuming this is because it is the centroid of the nearby riverbank area, however because the area is not convex, it does not necessarily enclose its own centroid. The simplest solution would probably be to test the calculated label point, and if it is not enclosed by the area, do not display it. ]

bhousel commented 9 years ago

ideas here: http://gis.stackexchange.com/questions/2128/algorithm-for-finding-irrregular-polygon-centroid-label-point

andyclegg commented 9 years ago

Another idea, taking advantage of iDs ability to draw labels along arbitrary paths. Break the area down into a polygon mesh of triangles. Find the centroid of each triangle. Draw the label along the imaginary path which connects these centroids.

bhousel commented 8 years ago

update: try @mourner's https://github.com/mapbox/polylabel

pnorman commented 2 years ago

https://github.com/mapbox/polylabel's PIA would work well.