diff --git a/docs/Changelog.md b/docs/Changelog.md index 56458353..c5ac0435 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -5,11 +5,12 @@ - Mapsforge themes compatibility [#100](https://github.com/mapsforge/vtm/issues/100) - Render themes: line symbol [#124](https://github.com/mapsforge/vtm/issues/124) - Render themes: stroke dash array [#131](https://github.com/mapsforge/vtm/issues/131) +- Polygon symbol positioning [#405](https://github.com/mapsforge/vtm/issues/405) - POI Search example [#394](https://github.com/mapsforge/vtm/issues/394) - Mapsforge Reverse Geocoding [#383](https://github.com/mapsforge/vtm/issues/383) - Core utilities [#396](https://github.com/mapsforge/vtm/issues/396) - Map scaling improvements [#401](https://github.com/mapsforge/vtm/issues/401) -- Mapsforge fix artifacts zoom > 17 [#231](https://github.com/mapsforge/vtm/issues/231) +- Mapsforge fix artifacts zoom >17 [#231](https://github.com/mapsforge/vtm/issues/231) - PolyLabel default disabled [#402](https://github.com/mapsforge/vtm/issues/402) - vtm-theme-comparator module [#387](https://github.com/mapsforge/vtm/issues/387) - Feature parameters [#403](https://github.com/mapsforge/vtm/issues/403) 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 dd9b8b8d..1a2d1a12 100644 --- a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java @@ -56,14 +56,14 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook { RenderStyle style, int level) { if (style instanceof TextStyle) { - LabelTileData ld = get(tile); - TextStyle text = (TextStyle) style.current(); - if (element.type == LINE) { - String value = element.tags.getValue(text.textKey); - if (value == null || value.length() == 0) - return false; + String value = element.tags.getValue(text.textKey); + if (value == null || value.length() == 0) + return false; + + LabelTileData ld = get(tile); + if (element.type == LINE) { int offset = 0; for (int i = 0, n = element.index.length; i < n; i++) { int length = element.index[i]; @@ -75,10 +75,6 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook { offset += length; } } else if (element.type == POLY) { - String value = element.tags.getValue(text.textKey); - 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)) @@ -114,10 +110,6 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook { ld.labels.push(TextItem.pool.get().set(x, y, value, text)); } else if (element.type == POINT) { - String value = element.tags.getValue(text.textKey); - if (value == null || value.length() == 0) - return false; - for (int i = 0, n = element.getNumPoints(); i < n; i++) { PointF p = element.getPoint(i); ld.labels.push(TextItem.pool.get().set(p.x, p.y, value, text)); @@ -130,8 +122,42 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook { return false; LabelTileData ld = get(tile); + if (element.type == LINE) { + // TODO + } else if (element.type == POLY) { + PointF centroid = element.labelPosition; + // skip unnecessary calculations if centroid is outside of visible area + if (centroid != null && (centroid.x < 0 || centroid.x > Tile.SIZE || centroid.y < 0 || centroid.y > Tile.SIZE)) + return false; - if (element.type == POINT) { + float x = 0; + float y = 0; + if (centroid == null) { + if (Parameters.POLY_LABEL) { + centroid = PolyLabel.get(element); + x = centroid.x; + y = centroid.y; + } else { + int n = element.index[0]; + for (int i = 0; i < n; ) { + x += element.points[i++]; + y += element.points[i++]; + } + x /= (n / 2); + y /= (n / 2); + } + } else { + x = centroid.x; + y = centroid.y; + } + + SymbolItem it = SymbolItem.pool.get(); + if (symbol.bitmap != null) + it.set(x, y, symbol.bitmap, true); + else + it.set(x, y, symbol.texture, true); + ld.symbols.push(it); + } else if (element.type == POINT) { for (int i = 0, n = element.getNumPoints(); i < n; i++) { PointF p = element.getPoint(i); @@ -142,22 +168,6 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook { it.set(p.x, p.y, symbol.texture, true); ld.symbols.push(it); } - } else if (element.type == LINE) { - //TODO: implement - } else if (element.type == POLY) { - PointF centroid = element.labelPosition; - if (centroid == null) - return false; - - if (centroid.x < 0 || centroid.x > Tile.SIZE || centroid.y < 0 || centroid.y > Tile.SIZE) - return false; - - SymbolItem it = SymbolItem.pool.get(); - if (symbol.bitmap != null) - it.set(centroid.x, centroid.y, symbol.bitmap, true); - else - it.set(centroid.x, centroid.y, symbol.texture, true); - ld.symbols.push(it); } } return false;