diff --git a/resources/rendertheme.xsd b/resources/rendertheme.xsd index 4d11511b..e9df52fe 100644 --- a/resources/rendertheme.xsd +++ b/resources/rendertheme.xsd @@ -143,10 +143,10 @@ - - + + @@ -220,6 +220,8 @@ + + diff --git a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java index b81cbec4..883f9c93 100644 --- a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java @@ -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); diff --git a/vtm/src/org/oscim/utils/geom/PolyLabel.java b/vtm/src/org/oscim/utils/geom/PolyLabel.java index 7eb40cac..cf328d70 100644 --- a/vtm/src/org/oscim/utils/geom/PolyLabel.java +++ b/vtm/src/org/oscim/utils/geom/PolyLabel.java @@ -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;