Render themes: allow symbols without texture atlas, closes #64

This commit is contained in:
Emux 2016-07-12 18:45:44 +03:00
parent 081e6b8f2b
commit 57a152d0aa
6 changed files with 74 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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,6 +474,9 @@ public class LabelPlacement {
continue;
SymbolItem s = SymbolItem.pool.get();
if (ti.bitmap != null)
s.bitmap = ti.bitmap;
else
s.texRegion = ti.texRegion;
s.x = x;
s.y = y;

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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,6 +109,9 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook {
PointF p = element.getPoint(i);
SymbolItem it = SymbolItem.pool.get();
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);
}

View File

@ -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 */

View File

@ -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,6 +235,7 @@ public class XmlThemeBuilder extends DefaultHandler {
} else if ("symbol".equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
SymbolStyle symbol = createSymbol(localName, attributes);
if (symbol != null)
mCurrentRule.addStyle(symbol);
} else if ("outline".equals(localName)) {
@ -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));
}

View File

@ -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