From 57a152d0aaea562b217d9ad9096323d3f95ef53e Mon Sep 17 00:00:00 2001 From: Emux Date: Tue, 12 Jul 2016 18:45:44 +0300 Subject: [PATCH] Render themes: allow symbols without texture atlas, closes #64 --- vtm-gdx/src/org/oscim/gdx/GdxAssets.java | 7 +++++- .../tile/vector/labeling/LabelPlacement.java | 23 +++++++++++++++++-- .../vector/labeling/LabelTileLoaderHook.java | 23 +++++++++++++++++-- .../oscim/renderer/bucket/SymbolBucket.java | 4 +++- vtm/src/org/oscim/theme/XmlThemeBuilder.java | 14 ++++++++++- .../org/oscim/theme/styles/SymbolStyle.java | 11 ++++++++- 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/vtm-gdx/src/org/oscim/gdx/GdxAssets.java b/vtm-gdx/src/org/oscim/gdx/GdxAssets.java index aad9abf2..ce8146d5 100644 --- a/vtm-gdx/src/org/oscim/gdx/GdxAssets.java +++ b/vtm-gdx/src/org/oscim/gdx/GdxAssets.java @@ -1,5 +1,6 @@ /* * Copyright 2013 Hannes Janetzek + * Copyright 2016 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -21,10 +22,14 @@ import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.GdxRuntimeException; import org.oscim.backend.AssetAdapter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.InputStream; public class GdxAssets extends AssetAdapter { + private static final Logger log = LoggerFactory.getLogger(GdxAssets.class); + static String pathPrefix = ""; private GdxAssets(String path) { @@ -40,7 +45,7 @@ public class GdxAssets extends AssetAdapter { try { return file.read(); } catch (GdxRuntimeException e) { - e.printStackTrace(); + log.debug(e.getMessage()); return null; } } diff --git a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java index f208ead3..3d33aba9 100644 --- a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 devemux86 + * + * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ package org.oscim.layers.tile.vector.labeling; import org.oscim.core.MapPosition; @@ -448,7 +464,7 @@ public class LabelPlacement { continue; for (SymbolItem ti : ld.symbols) { - if (ti.texRegion == null) + if (ti.bitmap == null && ti.texRegion == null) continue; int x = (int) ((dx + ti.x) * scale); @@ -458,7 +474,10 @@ public class LabelPlacement { continue; SymbolItem s = SymbolItem.pool.get(); - s.texRegion = ti.texRegion; + if (ti.bitmap != null) + s.bitmap = ti.bitmap; + else + s.texRegion = ti.texRegion; s.x = x; s.y = y; s.billboard = true; 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 297f4c17..88282388 100644 --- a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 devemux86 + * + * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ package org.oscim.layers.tile.vector.labeling; import org.oscim.core.MapElement; @@ -84,7 +100,7 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook { } else if ((element.type == POINT) && (style instanceof SymbolStyle)) { SymbolStyle symbol = (SymbolStyle) style; - if (symbol.texture == null) + if (symbol.bitmap == null && symbol.texture == null) return false; LabelTileData ld = get(tile); @@ -93,7 +109,10 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook { PointF p = element.getPoint(i); SymbolItem it = SymbolItem.pool.get(); - it.set(p.x, p.y, symbol.texture, true); + if (symbol.bitmap != null) + it.set(p.x, p.y, symbol.bitmap, true); + else + it.set(p.x, p.y, symbol.texture, true); ld.symbols.push(it); } } diff --git a/vtm/src/org/oscim/renderer/bucket/SymbolBucket.java b/vtm/src/org/oscim/renderer/bucket/SymbolBucket.java index 7833d995..e8d1ff4f 100644 --- a/vtm/src/org/oscim/renderer/bucket/SymbolBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/SymbolBucket.java @@ -1,5 +1,6 @@ /* * Copyright 2012 Hannes Janetzek + * Copyright 2016 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -79,8 +80,9 @@ public final class SymbolBucket extends TextureBucket { int x = 0; int y = 0; + // FIXME Use simultaneously TextureAtlas and external symbols if (it.texRegion != null) { - /* FIXME this work only with one TextureAtlas per SymbolLayer */ + /* FIXME This work only with one TextureAtlas per SymbolBucket */ if (textures == null) { /* clone TextureItem to use same texID with * multiple TextureItem */ diff --git a/vtm/src/org/oscim/theme/XmlThemeBuilder.java b/vtm/src/org/oscim/theme/XmlThemeBuilder.java index a1ef55b0..82d14c2e 100644 --- a/vtm/src/org/oscim/theme/XmlThemeBuilder.java +++ b/vtm/src/org/oscim/theme/XmlThemeBuilder.java @@ -55,6 +55,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.Locale; import java.util.Stack; import static java.lang.Boolean.parseBoolean; @@ -234,7 +235,8 @@ public class XmlThemeBuilder extends DefaultHandler { } else if ("symbol".equals(localName)) { checkState(localName, Element.RENDERING_INSTRUCTION); SymbolStyle symbol = createSymbol(localName, attributes); - mCurrentRule.addStyle(symbol); + if (symbol != null) + mCurrentRule.addStyle(symbol); } else if ("outline".equals(localName)) { checkState(localName, Element.RENDERING_INSTRUCTION); @@ -825,6 +827,16 @@ public class XmlThemeBuilder extends DefaultHandler { validateExists("src", src, elementName); + if (src.toLowerCase(Locale.ENGLISH).endsWith(".png")) { + try { + Bitmap bitmap = CanvasAdapter.getBitmapAsset(src); + if (bitmap != null) + return new SymbolStyle(bitmap); + } catch (Exception e) { + log.debug(e.getMessage()); + } + return null; + } return new SymbolStyle(getAtlasRegion(src)); } diff --git a/vtm/src/org/oscim/theme/styles/SymbolStyle.java b/vtm/src/org/oscim/theme/styles/SymbolStyle.java index 2fbe812c..a5f8ea85 100644 --- a/vtm/src/org/oscim/theme/styles/SymbolStyle.java +++ b/vtm/src/org/oscim/theme/styles/SymbolStyle.java @@ -1,6 +1,7 @@ /* * Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2013 Hannes Janetzek + * Copyright 2016 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -17,6 +18,7 @@ */ package org.oscim.theme.styles; +import org.oscim.backend.canvas.Bitmap; import org.oscim.renderer.atlas.TextureRegion; /** @@ -24,7 +26,12 @@ import org.oscim.renderer.atlas.TextureRegion; */ public final class SymbolStyle extends RenderStyle { - public final TextureRegion texture; + public Bitmap bitmap; + public TextureRegion texture; + + public SymbolStyle(Bitmap symbol) { + this.bitmap = symbol; + } public SymbolStyle(TextureRegion symbol) { this.texture = symbol; @@ -32,6 +39,8 @@ public final class SymbolStyle extends RenderStyle { @Override public void dispose() { + if (bitmap != null) + bitmap.recycle(); } @Override