parent
6461d39357
commit
2d3ab0b6fd
@ -32,6 +32,12 @@
|
||||
<activity
|
||||
android:name=".AtlasMultiTextureActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".AtlasThemeMapActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".AtlasThemeMapActivity$MapFilePicker"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".BitmapTileMapActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
|
@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright 2017 Longri
|
||||
* Copyright 2017 devemux86
|
||||
*
|
||||
* 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.android.test;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.oscim.android.filepicker.FilePicker;
|
||||
import org.oscim.android.filepicker.FilterByFileExtension;
|
||||
import org.oscim.android.filepicker.ValidMapFile;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.renderer.BitmapRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.scalebar.DefaultMapScaleBar;
|
||||
import org.oscim.scalebar.ImperialUnitAdapter;
|
||||
import org.oscim.scalebar.MapScaleBar;
|
||||
import org.oscim.scalebar.MapScaleBarLayer;
|
||||
import org.oscim.scalebar.MetricUnitAdapter;
|
||||
import org.oscim.theme.ThemeLoader;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.source.mapfile.MapFileTileSource;
|
||||
import org.oscim.tiling.source.mapfile.MapInfo;
|
||||
|
||||
public class AtlasThemeMapActivity extends MapActivity {
|
||||
private static final int SELECT_MAP_FILE = 0;
|
||||
|
||||
private TileGridLayer mGridLayer;
|
||||
private DefaultMapScaleBar mMapScaleBar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// set flag to use TextureAtlas for Theme-Symbol's!
|
||||
ThemeLoader.USE_ATLAS = true;
|
||||
|
||||
startActivityForResult(new Intent(this, MapFilePicker.class),
|
||||
SELECT_MAP_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
mMapScaleBar.destroy();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public static class MapFilePicker extends FilePicker {
|
||||
public MapFilePicker() {
|
||||
setFileDisplayFilter(new FilterByFileExtension(".map"));
|
||||
setFileSelectFilter(new ValidMapFile());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.theme_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.theme_default:
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
item.setChecked(true);
|
||||
return true;
|
||||
|
||||
case R.id.theme_osmarender:
|
||||
mMap.setTheme(VtmThemes.OSMARENDER);
|
||||
item.setChecked(true);
|
||||
return true;
|
||||
|
||||
case R.id.theme_osmagray:
|
||||
mMap.setTheme(VtmThemes.OSMAGRAY);
|
||||
item.setChecked(true);
|
||||
return true;
|
||||
|
||||
case R.id.theme_tubes:
|
||||
mMap.setTheme(VtmThemes.TRONRENDER);
|
||||
item.setChecked(true);
|
||||
return true;
|
||||
|
||||
case R.id.theme_newtron:
|
||||
mMap.setTheme(VtmThemes.NEWTRON);
|
||||
item.setChecked(true);
|
||||
return true;
|
||||
|
||||
case R.id.gridlayer:
|
||||
if (item.isChecked()) {
|
||||
item.setChecked(false);
|
||||
mMap.layers().remove(mGridLayer);
|
||||
} else {
|
||||
item.setChecked(true);
|
||||
if (mGridLayer == null)
|
||||
mGridLayer = new TileGridLayer(mMap, getResources().getDisplayMetrics().density);
|
||||
|
||||
mMap.layers().add(mGridLayer);
|
||||
}
|
||||
mMap.updateMap(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
|
||||
if (requestCode == SELECT_MAP_FILE) {
|
||||
if (resultCode != RESULT_OK || intent == null || intent.getStringExtra(FilePicker.SELECTED_FILE) == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
MapFileTileSource tileSource = new MapFileTileSource();
|
||||
tileSource.setPreferredLanguage("en");
|
||||
String file = intent.getStringExtra(FilePicker.SELECTED_FILE);
|
||||
if (tileSource.setMapFile(file)) {
|
||||
|
||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||
loadTheme(null);
|
||||
|
||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||
mMap.layers().add(new LabelLayer(mMap, l));
|
||||
|
||||
mMapScaleBar = new DefaultMapScaleBar(mMap);
|
||||
mMapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
|
||||
mMapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
|
||||
mMapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
|
||||
mMapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
|
||||
|
||||
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mMapScaleBar);
|
||||
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
|
||||
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
|
||||
renderer.setOffset(5 * getResources().getDisplayMetrics().density, 0);
|
||||
mMap.layers().add(mapScaleBarLayer);
|
||||
|
||||
MapInfo info = tileSource.getMapInfo();
|
||||
MapPosition pos = new MapPosition();
|
||||
pos.setByBoundingBox(info.boundingBox, Tile.SIZE * 4, Tile.SIZE * 4);
|
||||
mMap.setMapPosition(pos);
|
||||
|
||||
mPrefs.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadTheme(final String styleId) {
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
}
|
||||
}
|
@ -46,6 +46,7 @@ public class Samples extends Activity {
|
||||
linearLayout.addView(createButton(MapsforgeStyleActivity.class));
|
||||
linearLayout.addView(createButton(MapboxMapActivity.class));
|
||||
linearLayout.addView(createButton(OsmJsonMapActivity.class));
|
||||
linearLayout.addView(createButton(AtlasThemeMapActivity.class));
|
||||
|
||||
linearLayout.addView(createLabel("Raster Maps"));
|
||||
linearLayout.addView(createButton(BitmapTileMapActivity.class));
|
||||
|
73
vtm-playground/src/org/oscim/test/AtlasThemeTest.java
Normal file
73
vtm-playground/src/org/oscim/test/AtlasThemeTest.java
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2017 Longri
|
||||
* Copyright 2017 devemux86
|
||||
*
|
||||
* 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.test;
|
||||
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.GroupLayer;
|
||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.BitmapRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.scalebar.DefaultMapScaleBar;
|
||||
import org.oscim.scalebar.ImperialUnitAdapter;
|
||||
import org.oscim.scalebar.MapScaleBar;
|
||||
import org.oscim.scalebar.MapScaleBarLayer;
|
||||
import org.oscim.scalebar.MetricUnitAdapter;
|
||||
import org.oscim.theme.ThemeLoader;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
|
||||
public class AtlasThemeTest extends GdxMapApp {
|
||||
|
||||
public AtlasThemeTest() {
|
||||
// set flag to use TextureAtlas for Theme symbols
|
||||
ThemeLoader.USE_ATLAS = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
Map map = getMap();
|
||||
|
||||
VectorTileLayer l = map.setBaseMap(new OSciMap4TileSource());
|
||||
|
||||
GroupLayer groupLayer = new GroupLayer(mMap);
|
||||
groupLayer.layers.add(new BuildingLayer(map, l));
|
||||
groupLayer.layers.add(new LabelLayer(map, l));
|
||||
map.layers().add(groupLayer);
|
||||
|
||||
DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap);
|
||||
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
|
||||
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
|
||||
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
|
||||
mapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
|
||||
|
||||
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
|
||||
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
|
||||
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
|
||||
renderer.setOffset(5, 0);
|
||||
map.layers().add(mapScaleBarLayer);
|
||||
|
||||
map.setTheme(VtmThemes.DEFAULT);
|
||||
map.setMapPosition(53.075, 8.808, 1 << 17);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new AtlasThemeTest());
|
||||
}
|
||||
}
|
45
vtm/src/org/oscim/theme/AtlasRenderTheme.java
Normal file
45
vtm/src/org/oscim/theme/AtlasRenderTheme.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* 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.theme;
|
||||
|
||||
import org.oscim.renderer.atlas.TextureAtlas;
|
||||
import org.oscim.renderer.atlas.TextureRegion;
|
||||
import org.oscim.theme.rule.Rule;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AtlasRenderTheme extends RenderTheme {
|
||||
|
||||
private final Map<Object, TextureRegion> textureRegionMap;
|
||||
private final List<TextureAtlas> atlasList;
|
||||
|
||||
public AtlasRenderTheme(int mapBackground, float baseTextSize, Rule[] rules, int levels,
|
||||
Map<Object, TextureRegion> textureRegionMap, List<TextureAtlas> atlasList) {
|
||||
super(mapBackground, baseTextSize, rules, levels);
|
||||
this.textureRegionMap = textureRegionMap;
|
||||
this.atlasList = atlasList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
for (TextureAtlas atlas : atlasList) {
|
||||
atlas.clear();
|
||||
atlas.texture.dispose();
|
||||
}
|
||||
textureRegionMap.clear();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -107,6 +108,10 @@ public class RenderTheme implements IRenderTheme {
|
||||
return mMapBackground;
|
||||
}
|
||||
|
||||
Rule[] getRules() {
|
||||
return mRules;
|
||||
}
|
||||
|
||||
//AtomicInteger hitCount = new AtomicInteger(0);
|
||||
//AtomicInteger missCount = new AtomicInteger(0);
|
||||
//AtomicInteger sameCount = new AtomicInteger(0);
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -22,6 +23,8 @@ import org.oscim.theme.IRenderTheme.ThemeException;
|
||||
|
||||
public class ThemeLoader {
|
||||
|
||||
public static boolean USE_ATLAS;
|
||||
|
||||
public static IRenderTheme load(String renderThemePath) throws ThemeException {
|
||||
return load(new ExternalRenderTheme(renderThemePath));
|
||||
}
|
||||
@ -43,7 +46,7 @@ public class ThemeLoader {
|
||||
}
|
||||
|
||||
public static IRenderTheme load(ThemeFile theme, ThemeCallback themeCallback) throws ThemeException {
|
||||
IRenderTheme t = XmlThemeBuilder.read(theme, themeCallback);
|
||||
IRenderTheme t = USE_ATLAS ? XmlAtlasThemeBuilder.read(theme, themeCallback) : XmlThemeBuilder.read(theme, themeCallback);
|
||||
if (t != null)
|
||||
t.scaleTextSize(CanvasAdapter.textScale + (CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI - 1));
|
||||
return t;
|
||||
|
170
vtm/src/org/oscim/theme/XmlAtlasThemeBuilder.java
Normal file
170
vtm/src/org/oscim/theme/XmlAtlasThemeBuilder.java
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* 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.theme;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.Platform;
|
||||
import org.oscim.backend.XMLReaderAdapter;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.renderer.atlas.TextureAtlas;
|
||||
import org.oscim.renderer.atlas.TextureRegion;
|
||||
import org.oscim.theme.rule.Rule;
|
||||
import org.oscim.theme.styles.RenderStyle;
|
||||
import org.oscim.theme.styles.SymbolStyle;
|
||||
import org.oscim.utils.TextureAtlasUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class XmlAtlasThemeBuilder extends XmlThemeBuilder {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(XmlAtlasThemeBuilder.class);
|
||||
|
||||
private final Map<Object, Bitmap> bitmapMap = new HashMap<>();
|
||||
private final Map<Object, TextureRegion> outputMap;
|
||||
private final List<TextureAtlas> atlasList;
|
||||
|
||||
public XmlAtlasThemeBuilder(ThemeFile theme, ThemeCallback themeCallback,
|
||||
Map<Object, TextureRegion> outputMap, List<TextureAtlas> atlasList) {
|
||||
super(theme, themeCallback);
|
||||
this.outputMap = outputMap;
|
||||
this.atlasList = atlasList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param theme an input theme containing valid render theme XML data.
|
||||
* @param themeCallback the theme callback.
|
||||
* @return a new RenderTheme which is created by parsing the XML data from the input theme.
|
||||
* @throws IRenderTheme.ThemeException if an error occurs while parsing the render theme XML.
|
||||
*/
|
||||
public static IRenderTheme read(ThemeFile theme, ThemeCallback themeCallback) throws IRenderTheme.ThemeException {
|
||||
Map<Object, TextureRegion> outputMap = new HashMap<>();
|
||||
List<TextureAtlas> atlasList = new ArrayList<>();
|
||||
XmlAtlasThemeBuilder renderThemeHandler = new XmlAtlasThemeBuilder(theme, themeCallback, outputMap, atlasList);
|
||||
|
||||
try {
|
||||
new XMLReaderAdapter().parse(renderThemeHandler, theme.getRenderThemeAsStream());
|
||||
} catch (Exception e) {
|
||||
throw new IRenderTheme.ThemeException(e.getMessage());
|
||||
}
|
||||
|
||||
TextureAtlasUtils.createTextureRegions(renderThemeHandler.bitmapMap, outputMap, atlasList,
|
||||
true, CanvasAdapter.platform == Platform.IOS);
|
||||
|
||||
return replaceSymbolStylesOnTheme(outputMap, renderThemeHandler.mRenderTheme);
|
||||
}
|
||||
|
||||
private static IRenderTheme replaceSymbolStylesOnTheme(Map<Object, TextureRegion> regionMap, RenderTheme theme) {
|
||||
SymbolStyle.SymbolBuilder<?> symbolBuilder = new SymbolStyle.SymbolBuilder();
|
||||
Rule[] rules = theme.getRules();
|
||||
for (Rule rule : rules) {
|
||||
replaceSymbolStylesOnRules(regionMap, symbolBuilder, rule);
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
private static void replaceSymbolStylesOnRules(Map<Object, TextureRegion> regionMap,
|
||||
SymbolStyle.SymbolBuilder<?> symbolBuilder, Rule rule) {
|
||||
for (int i = 0, n = rule.styles.length; i < n; i++) {
|
||||
RenderStyle style = rule.styles[i];
|
||||
if (style instanceof SymbolStyle) {
|
||||
String sourceName = ((SymbolStyle) style).sourceName;
|
||||
|
||||
TextureRegion region = regionMap.get(sourceName);
|
||||
if (region != null) {
|
||||
symbolBuilder = symbolBuilder.reset();
|
||||
rule.styles[i] = symbolBuilder.texture(region).build();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
for (Rule subRule : rule.subRules) {
|
||||
replaceSymbolStylesOnRules(regionMap, symbolBuilder, subRule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new Symbol with the given rendering attributes.
|
||||
*/
|
||||
protected SymbolStyle createSymbol(String elementName, Attributes attributes) {
|
||||
SymbolStyle.SymbolBuilder<?> b = mSymbolBuilder.reset();
|
||||
String src = null;
|
||||
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
String name = attributes.getLocalName(i);
|
||||
String value = attributes.getValue(i);
|
||||
|
||||
if ("src".equals(name))
|
||||
src = value;
|
||||
|
||||
else if ("cat".equals(name))
|
||||
b.cat(value);
|
||||
|
||||
else if ("symbol-width".equals(name))
|
||||
b.symbolWidth = (int) (Integer.parseInt(value) * mScale);
|
||||
|
||||
else if ("symbol-height".equals(name))
|
||||
b.symbolHeight = (int) (Integer.parseInt(value) * mScale);
|
||||
|
||||
else if ("symbol-percent".equals(name))
|
||||
b.symbolPercent = Integer.parseInt(value);
|
||||
|
||||
else
|
||||
logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
|
||||
validateExists("src", src, elementName);
|
||||
|
||||
String lowSrc = src.toLowerCase(Locale.ENGLISH);
|
||||
if (lowSrc.endsWith(".png") || lowSrc.endsWith(".svg")) {
|
||||
try {
|
||||
Bitmap bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
if (bitmap != null) {
|
||||
//create a property depends name! (needed if the same image used with different sizes)
|
||||
String sourceName = lowSrc + b.symbolWidth + "/" + b.symbolHeight + "/" + b.symbolPercent;
|
||||
bitmapMap.put(sourceName, bitmap);
|
||||
return b.sourceName(sourceName).build();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return b.texture(getAtlasRegion(src)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endDocument() {
|
||||
Rule[] rules = new Rule[mRulesList.size()];
|
||||
for (int i = 0, n = rules.length; i < n; i++)
|
||||
rules[i] = mRulesList.get(i).onComplete(null);
|
||||
|
||||
mRenderTheme = new AtlasRenderTheme(mMapBackground, mTextScale, rules, mLevels, this.outputMap, this.atlasList);
|
||||
|
||||
mRulesList.clear();
|
||||
mStyles.clear();
|
||||
mRuleStack.clear();
|
||||
mElementStack.clear();
|
||||
|
||||
mTextureAtlas = null;
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016-2017 devemux86
|
||||
* Copyright 2016 Longri
|
||||
* Copyright 2016-2017 Longri
|
||||
* Copyright 2016 Andrey Novikov
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
@ -120,16 +120,16 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
* @param value the XML attribute value.
|
||||
* @param attributeIndex the XML attribute index position.
|
||||
*/
|
||||
private static void logUnknownAttribute(String element, String name,
|
||||
String value, int attributeIndex) {
|
||||
static void logUnknownAttribute(String element, String name,
|
||||
String value, int attributeIndex) {
|
||||
log.debug("unknown attribute in element {} () : {} = {}",
|
||||
element, attributeIndex, name, value);
|
||||
}
|
||||
|
||||
private final ArrayList<RuleBuilder> mRulesList = new ArrayList<>();
|
||||
private final Stack<Element> mElementStack = new Stack<>();
|
||||
private final Stack<RuleBuilder> mRuleStack = new Stack<>();
|
||||
private final HashMap<String, RenderStyle> mStyles = new HashMap<>(10);
|
||||
final ArrayList<RuleBuilder> mRulesList = new ArrayList<>();
|
||||
final Stack<Element> mElementStack = new Stack<>();
|
||||
final Stack<RuleBuilder> mRuleStack = new Stack<>();
|
||||
final HashMap<String, RenderStyle> mStyles = new HashMap<>(10);
|
||||
|
||||
private final HashMap<String, TextStyle.TextBuilder<?>> mTextStyles = new HashMap<>(10);
|
||||
|
||||
@ -137,21 +137,22 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
private final CircleBuilder<?> mCircleBuilder = CircleStyle.builder();
|
||||
private final ExtrusionBuilder<?> mExtrusionBuilder = ExtrusionStyle.builder();
|
||||
private final LineBuilder<?> mLineBuilder = LineStyle.builder();
|
||||
private final SymbolBuilder<?> mSymbolBuilder = SymbolStyle.builder();
|
||||
final SymbolBuilder<?> mSymbolBuilder = SymbolStyle.builder();
|
||||
private final TextBuilder<?> mTextBuilder = TextStyle.builder();
|
||||
|
||||
private RuleBuilder mCurrentRule;
|
||||
private TextureAtlas mTextureAtlas;
|
||||
TextureAtlas mTextureAtlas;
|
||||
|
||||
private int mLevels = 0;
|
||||
private int mMapBackground = 0xffffffff;
|
||||
private float mTextScale = 1;
|
||||
int mLevels = 0;
|
||||
int mMapBackground = 0xffffffff;
|
||||
float mTextScale = 1;
|
||||
|
||||
private final ThemeFile mTheme;
|
||||
final ThemeFile mTheme;
|
||||
private final ThemeCallback mThemeCallback;
|
||||
private RenderTheme mRenderTheme;
|
||||
RenderTheme mRenderTheme;
|
||||
|
||||
private final float mScale, mScale2;
|
||||
final float mScale;
|
||||
private final float mScale2;
|
||||
|
||||
private Set<String> mCategories;
|
||||
private XmlRenderThemeStyleLayer mCurrentLayer;
|
||||
@ -424,7 +425,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
return b;
|
||||
}
|
||||
|
||||
private TextureRegion getAtlasRegion(String src) {
|
||||
TextureRegion getAtlasRegion(String src) {
|
||||
if (mTextureAtlas == null)
|
||||
return null;
|
||||
|
||||
@ -1007,7 +1008,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
/**
|
||||
* @return a new Symbol with the given rendering attributes.
|
||||
*/
|
||||
private SymbolStyle createSymbol(String elementName, Attributes attributes) {
|
||||
SymbolStyle createSymbol(String elementName, Attributes attributes) {
|
||||
SymbolBuilder<?> b = mSymbolBuilder.reset();
|
||||
String src = null;
|
||||
|
||||
@ -1112,7 +1113,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
+ value);
|
||||
}
|
||||
|
||||
private static void validateExists(String name, Object obj, String elementName) {
|
||||
static void validateExists(String name, Object obj, String elementName) {
|
||||
if (obj == null)
|
||||
throw new ThemeException("missing attribute " + name
|
||||
+ " for element: " + elementName);
|
||||
|
@ -2,6 +2,7 @@
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -26,6 +27,7 @@ import org.oscim.renderer.atlas.TextureRegion;
|
||||
*/
|
||||
public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
|
||||
public final String sourceName;
|
||||
public final Bitmap bitmap;
|
||||
public final TextureRegion texture;
|
||||
|
||||
@ -34,6 +36,7 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
public final int symbolPercent;
|
||||
|
||||
public SymbolStyle(Bitmap bitmap) {
|
||||
this.sourceName = null;
|
||||
this.bitmap = bitmap;
|
||||
this.texture = null;
|
||||
|
||||
@ -43,6 +46,7 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
}
|
||||
|
||||
public SymbolStyle(TextureRegion texture) {
|
||||
this.sourceName = null;
|
||||
this.bitmap = null;
|
||||
this.texture = texture;
|
||||
|
||||
@ -51,7 +55,18 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
this.symbolPercent = 100;
|
||||
}
|
||||
|
||||
public SymbolStyle(String sourceName) {
|
||||
this.sourceName = sourceName;
|
||||
this.bitmap = null;
|
||||
this.texture = null;
|
||||
|
||||
this.symbolWidth = 0;
|
||||
this.symbolHeight = 0;
|
||||
this.symbolPercent = 100;
|
||||
}
|
||||
|
||||
public SymbolStyle(SymbolBuilder<?> b) {
|
||||
this.sourceName = b.sourceName;
|
||||
this.bitmap = b.bitmap;
|
||||
this.texture = b.texture;
|
||||
|
||||
@ -83,6 +98,7 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
|
||||
public static class SymbolBuilder<T extends SymbolBuilder<T>> extends StyleBuilder<T> {
|
||||
|
||||
public String sourceName;
|
||||
public Bitmap bitmap;
|
||||
public TextureRegion texture;
|
||||
|
||||
@ -117,6 +133,11 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
return self();
|
||||
}
|
||||
|
||||
public T sourceName(String sourceName) {
|
||||
this.sourceName = sourceName;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T symbolWidth(int symbolWidth) {
|
||||
this.symbolWidth = symbolWidth;
|
||||
return self();
|
||||
@ -135,6 +156,7 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
public T reset() {
|
||||
bitmap = null;
|
||||
texture = null;
|
||||
sourceName = null;
|
||||
|
||||
symbolWidth = 0;
|
||||
symbolHeight = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user