- Fix infinite recursion on invalid polygons - Allow setting area-size for text styles - Skip unnecessary calculations if label is outside of visible area
This commit is contained in:
parent
cbd0ac01df
commit
97654f0670
@ -143,10 +143,10 @@
|
||||
<xs:attribute name="fill" default="#000000" type="tns:color" use="optional" />
|
||||
<xs:attribute name="stroke" default="#000000" type="tns:color" use="optional" />
|
||||
<xs:attribute name="stroke-width" default="0" type="tns:nonNegativeFloat" use="optional" />
|
||||
<!-- priority for label placement, 0 = highest priority -->
|
||||
<xs:attribute name="priority" default="0" type="xs:integer" use="optional" />
|
||||
<!-- polygon area expressed as a ratio to tile area, e.g. 0.1 for 10% of tile area -->
|
||||
<xs:attribute name="area-size" default="0" type="tns:nonNegativeFloat" use="optional" />
|
||||
<!-- priority for label placement, 0 = highest priority -->
|
||||
<xs:attribute name="priority" default="0" type="xs:integer" use="optional" />
|
||||
<!-- symbol src name in atlas -->
|
||||
<xs:attribute name="symbol" type="tns:src" use="optional" />
|
||||
</xs:complexType>
|
||||
@ -220,6 +220,8 @@
|
||||
<xs:attribute name="stroke" default="#000000" type="tns:color" use="optional" />
|
||||
<xs:attribute name="stroke-width" default="0" type="tns:nonNegativeFloat" use="optional" />
|
||||
<xs:attribute name="caption" default="false" type="xs:boolean" use="optional" />
|
||||
<!-- polygon area expressed as a ratio to tile area, e.g. 0.1 for 10% of tile area -->
|
||||
<xs:attribute name="area-size" default="0" type="tns:nonNegativeFloat" use="optional" />
|
||||
<!-- priority for label placement, 0 = highest priority -->
|
||||
<xs:attribute name="priority" default="0" type="xs:integer" use="optional" />
|
||||
</xs:complexType>
|
||||
|
@ -77,6 +77,11 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook {
|
||||
if (value == null || value.length() == 0)
|
||||
return false;
|
||||
|
||||
PointF label = element.labelPosition;
|
||||
// skip unnecessary calculations if label is outside of visible area
|
||||
if (label != null && (label.x < 0 || label.x > Tile.SIZE || label.y < 0 || label.y > Tile.SIZE))
|
||||
return false;
|
||||
|
||||
if (text.areaSize > 0f) {
|
||||
float area = element.area();
|
||||
float ratio = area / (Tile.SIZE * Tile.SIZE); // we can't use static as it's recalculated based on dpi
|
||||
@ -84,13 +89,9 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook {
|
||||
return false;
|
||||
}
|
||||
|
||||
PointF label = element.labelPosition;
|
||||
if (label == null)
|
||||
label = PolyLabel.get(element);
|
||||
|
||||
if (label.x < 0 || label.x > Tile.SIZE || label.y < 0 || label.y > Tile.SIZE)
|
||||
return false;
|
||||
|
||||
ld.labels.push(TextItem.pool.get().set(label.x, label.y, value, text));
|
||||
} else if (element.type == POINT) {
|
||||
String value = element.tags.getValue(text.textKey);
|
||||
|
@ -43,6 +43,13 @@ public class PolyLabel {
|
||||
// find the bounding box of the outer ring
|
||||
float minX = Float.MAX_VALUE, minY = Float.MAX_VALUE, maxX = Float.MIN_VALUE, maxY = Float.MIN_VALUE;
|
||||
|
||||
// take centroid as the first best guess
|
||||
Cell bestCell = getCentroidCell(polygon);
|
||||
|
||||
// if polygon is clipped to a line, return invalid label point
|
||||
if (Float.isNaN(bestCell.x) || Float.isNaN(bestCell.y))
|
||||
return new PointF(-1f, -1f);
|
||||
|
||||
int n = polygon.index[0];
|
||||
|
||||
for (int i = 0; i < n; ) {
|
||||
@ -69,9 +76,6 @@ public class PolyLabel {
|
||||
}
|
||||
}
|
||||
|
||||
// take centroid as the first best guess
|
||||
Cell bestCell = getCentroidCell(polygon);
|
||||
|
||||
// special case for rectangular polygons
|
||||
Cell bboxCell = new Cell(minX + width / 2, minY + height / 2, 0, polygon);
|
||||
if (bboxCell.d > bestCell.d) bestCell = bboxCell;
|
||||
|
Loading…
x
Reference in New Issue
Block a user