Render themes: allow symbols without texture atlas, closes #64
This commit is contained in:
parent
081e6b8f2b
commit
57a152d0aa
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* 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 com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
|
|
||||||
import org.oscim.backend.AssetAdapter;
|
import org.oscim.backend.AssetAdapter;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class GdxAssets extends AssetAdapter {
|
public class GdxAssets extends AssetAdapter {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(GdxAssets.class);
|
||||||
|
|
||||||
static String pathPrefix = "";
|
static String pathPrefix = "";
|
||||||
|
|
||||||
private GdxAssets(String path) {
|
private GdxAssets(String path) {
|
||||||
@ -40,7 +45,7 @@ public class GdxAssets extends AssetAdapter {
|
|||||||
try {
|
try {
|
||||||
return file.read();
|
return file.read();
|
||||||
} catch (GdxRuntimeException e) {
|
} catch (GdxRuntimeException e) {
|
||||||
e.printStackTrace();
|
log.debug(e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package org.oscim.layers.tile.vector.labeling;
|
||||||
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
@ -448,7 +464,7 @@ public class LabelPlacement {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (SymbolItem ti : ld.symbols) {
|
for (SymbolItem ti : ld.symbols) {
|
||||||
if (ti.texRegion == null)
|
if (ti.bitmap == null && ti.texRegion == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int x = (int) ((dx + ti.x) * scale);
|
int x = (int) ((dx + ti.x) * scale);
|
||||||
@ -458,7 +474,10 @@ public class LabelPlacement {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
SymbolItem s = SymbolItem.pool.get();
|
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.x = x;
|
||||||
s.y = y;
|
s.y = y;
|
||||||
s.billboard = true;
|
s.billboard = true;
|
||||||
|
@ -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;
|
package org.oscim.layers.tile.vector.labeling;
|
||||||
|
|
||||||
import org.oscim.core.MapElement;
|
import org.oscim.core.MapElement;
|
||||||
@ -84,7 +100,7 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook {
|
|||||||
} else if ((element.type == POINT) && (style instanceof SymbolStyle)) {
|
} else if ((element.type == POINT) && (style instanceof SymbolStyle)) {
|
||||||
SymbolStyle symbol = (SymbolStyle) style;
|
SymbolStyle symbol = (SymbolStyle) style;
|
||||||
|
|
||||||
if (symbol.texture == null)
|
if (symbol.bitmap == null && symbol.texture == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LabelTileData ld = get(tile);
|
LabelTileData ld = get(tile);
|
||||||
@ -93,7 +109,10 @@ public class LabelTileLoaderHook implements TileLoaderThemeHook {
|
|||||||
PointF p = element.getPoint(i);
|
PointF p = element.getPoint(i);
|
||||||
|
|
||||||
SymbolItem it = SymbolItem.pool.get();
|
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);
|
ld.symbols.push(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012 Hannes Janetzek
|
* Copyright 2012 Hannes Janetzek
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* 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 x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
|
// FIXME Use simultaneously TextureAtlas and external symbols
|
||||||
if (it.texRegion != null) {
|
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) {
|
if (textures == null) {
|
||||||
/* clone TextureItem to use same texID with
|
/* clone TextureItem to use same texID with
|
||||||
* multiple TextureItem */
|
* multiple TextureItem */
|
||||||
|
@ -55,6 +55,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import static java.lang.Boolean.parseBoolean;
|
import static java.lang.Boolean.parseBoolean;
|
||||||
@ -234,7 +235,8 @@ public class XmlThemeBuilder extends DefaultHandler {
|
|||||||
} else if ("symbol".equals(localName)) {
|
} else if ("symbol".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
SymbolStyle symbol = createSymbol(localName, attributes);
|
SymbolStyle symbol = createSymbol(localName, attributes);
|
||||||
mCurrentRule.addStyle(symbol);
|
if (symbol != null)
|
||||||
|
mCurrentRule.addStyle(symbol);
|
||||||
|
|
||||||
} else if ("outline".equals(localName)) {
|
} else if ("outline".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
@ -825,6 +827,16 @@ public class XmlThemeBuilder extends DefaultHandler {
|
|||||||
|
|
||||||
validateExists("src", src, elementName);
|
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));
|
return new SymbolStyle(getAtlasRegion(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -17,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.theme.styles;
|
package org.oscim.theme.styles;
|
||||||
|
|
||||||
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
import org.oscim.renderer.atlas.TextureRegion;
|
import org.oscim.renderer.atlas.TextureRegion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +26,12 @@ import org.oscim.renderer.atlas.TextureRegion;
|
|||||||
*/
|
*/
|
||||||
public final class SymbolStyle extends RenderStyle {
|
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) {
|
public SymbolStyle(TextureRegion symbol) {
|
||||||
this.texture = symbol;
|
this.texture = symbol;
|
||||||
@ -32,6 +39,8 @@ public final class SymbolStyle extends RenderStyle {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
if (bitmap != null)
|
||||||
|
bitmap.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user