Better label placement for polygons #878

Merged
merged 2 commits into from Jul 30, 2013

2 participants

@ahocevar
OpenLayers member

Using the y-coordinate of the polygon's bounding box, this
simple algorithm intersects the polygon with the horizontal
center line of its bounding box. The x-coordinate of the label
point is the center of the longest segment of this intersection
that is inside the polygon.

@ahocevar ahocevar Better label placement for polygons
Using the y-coordinate of the polygon's bounding box, this
simple algorithm intersects the polygon with the horizontal
center line of its bounding box. The x-coordinate of the label
point is the center of the longest segment of this intersection
that is inside the polygon.
11ef2cb
@tschaub
OpenLayers member

Looks good to me. I'd be tempted to call the method getInteriorPoint since it doesn't have anything else to do with labeling (doesn't consider label length, do conflict detection, etc.) and giving geometries methods or properties that have to do with rendering is a bit odd. As a bonus, this would bring it closer to the JTS method that is its inspiration.

Either way, this isn't exported and can change or be removed in the future. Please merge.

@ahocevar ahocevar Renaming method to getInteriorPoint
as suggested by @tschaub. Also giving credit to JTS.
b2e25c8
@ahocevar ahocevar merged commit 53765eb into openlayers:master Jul 30, 2013

1 check passed

Details default The Travis CI build passed
@ahocevar ahocevar deleted the ahocevar:polygon-labels branch Jul 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment