Use baseline 160dpi in scaling, closes #236

This commit is contained in:
Emux 2016-11-13 12:23:32 +02:00
parent d82faad435
commit 58b5f2741b
24 changed files with 56 additions and 55 deletions

View File

@ -6,6 +6,7 @@
- Polygon label position enhancements [#80](https://github.com/mapsforge/vtm/issues/80)
- PathLayer (vtm) fix disappearing segments [#108](https://github.com/mapsforge/vtm/issues/108)
- House numbers (nodes) fix visibility [#168](https://github.com/mapsforge/vtm/issues/168)
- Use baseline 160dpi in scaling [#236](https://github.com/mapsforge/vtm/issues/236)
- MapFileTileSource zoom level API enhancements [#219](https://github.com/mapsforge/vtm/issues/219)
- Tile grid layer scaling [#238](https://github.com/mapsforge/vtm/issues/238)
- Internal render themes various improvements [#41](https://github.com/mapsforge/vtm/issues/41)

View File

@ -22,7 +22,6 @@ import android.view.Menu;
import android.view.MenuItem;
import org.oscim.android.cache.TileCache;
import org.oscim.backend.CanvasAdapter;
import org.oscim.core.MapPosition;
import org.oscim.layers.TileGridLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@ -109,7 +108,7 @@ public class BaseMapActivity extends MapActivity {
} else {
item.setChecked(true);
if (mGridLayer == null)
mGridLayer = new TileGridLayer(mMap, CanvasAdapter.dpi / 160);
mGridLayer = new TileGridLayer(mMap, getResources().getDisplayMetrics().density);
mMap.layers().add(mGridLayer);
}

View File

@ -20,7 +20,6 @@ package org.oscim.android.test;
import android.os.Bundle;
import org.oscim.backend.CanvasAdapter;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.map.Layers;
@ -53,7 +52,7 @@ public class LayerGroupActivity extends BaseMapActivity {
layers.addGroup(GROUP_LABELS);
layers.add(new LabelLayer(mMap, mBaseLayer), GROUP_LABELS);
mapScaleBar = new DefaultMapScaleBar(mMap, CanvasAdapter.dpi / 160);
mapScaleBar = new DefaultMapScaleBar(mMap);
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
@ -62,7 +61,7 @@ public class LayerGroupActivity extends BaseMapActivity {
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5 * CanvasAdapter.dpi / 160, 0);
renderer.setOffset(5 * getResources().getDisplayMetrics().density, 0);
layers.addGroup(GROUP_OVERLAYS);
layers.add(mapScaleBarLayer, GROUP_OVERLAYS);

View File

@ -25,7 +25,6 @@ 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.backend.CanvasAdapter;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.layers.TileGridLayer;
@ -93,7 +92,7 @@ public class MapsforgeMapActivity extends MapActivity {
} else {
item.setChecked(true);
if (mGridLayer == null)
mGridLayer = new TileGridLayer(mMap, CanvasAdapter.dpi / 160);
mGridLayer = new TileGridLayer(mMap, getResources().getDisplayMetrics().density);
mMap.layers().add(mGridLayer);
}

View File

@ -21,7 +21,6 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Toast;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.core.GeoPoint;
import org.oscim.layers.TileGridLayer;
@ -82,7 +81,7 @@ public class MarkerOverlayActivity extends BitmapTileMapActivity
markerLayer.addItems(pts);
mMap.layers().add(new TileGridLayer(mMap, CanvasAdapter.dpi / 160));
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density));
}
@Override

View File

@ -19,7 +19,6 @@ package org.oscim.android.test;
import android.os.Bundle;
import org.oscim.backend.CanvasAdapter;
import org.oscim.layers.TileGridLayer;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@ -66,7 +65,7 @@ public class OsmJsonMapActivity extends MapActivity {
mMap.layers().add(l);
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new TileGridLayer(mMap, CanvasAdapter.dpi / 160));
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density));
mMap.setMapPosition(53.08, 8.83, Math.pow(2, 16));
}

View File

@ -19,7 +19,6 @@ package org.oscim.android.test;
import android.os.Bundle;
import org.oscim.backend.CanvasAdapter;
import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;
import org.oscim.layers.GroupLayer;
@ -48,7 +47,7 @@ public class SimpleMapActivity extends BaseMapActivity {
groupLayer.layers.add(new LabelLayer(mMap, mBaseLayer));
mMap.layers().add(groupLayer);
mapScaleBar = new DefaultMapScaleBar(mMap, CanvasAdapter.dpi / 160);
mapScaleBar = new DefaultMapScaleBar(mMap);
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
@ -57,7 +56,7 @@ public class SimpleMapActivity extends BaseMapActivity {
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5 * CanvasAdapter.dpi / 160, 0);
renderer.setOffset(5 * getResources().getDisplayMetrics().density, 0);
mMap.layers().add(mapScaleBarLayer);
mMap.setTheme(VtmThemes.DEFAULT);

View File

@ -58,7 +58,7 @@ public class MainActivity extends AndroidApplication {
@Override
public void createLayers() {
TileSource ts = new OSciMap4TileSource();
initDefaultLayers(ts, true, true, true, CanvasAdapter.dpi / 160);
initDefaultLayers(ts, true, true, true, getResources().getDisplayMetrics().density);
}
}
}

View File

@ -76,7 +76,7 @@ public class AndroidSvgBitmap extends AndroidBitmap {
private static android.graphics.Bitmap getResourceBitmapImpl(InputStream inputStream) throws IOException {
synchronized (SVG.getVersion()) {
return getResourceBitmap(inputStream, CanvasAdapter.dpi / 160, DEFAULT_SIZE, 0, 0, 100);
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, 0, 0, 100);
}
}

View File

@ -21,7 +21,6 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.oscim.android.cache.TileCache;
import org.oscim.backend.CanvasAdapter;
import org.oscim.layers.GenericLayer;
import org.oscim.layers.Layer;
import org.oscim.layers.TileGridLayer;
@ -149,13 +148,13 @@ public class MapLayers {
}
void enableGridOverlay(boolean enable) {
void enableGridOverlay(Context context, boolean enable) {
if (mGridEnabled == enable)
return;
if (enable) {
if (mGridOverlay == null)
mGridOverlay = new TileGridLayer(App.map, CanvasAdapter.dpi / 160);
mGridOverlay = new TileGridLayer(App.map, context.getResources().getDisplayMetrics().density);
App.map.layers().add(mGridOverlay);
} else {

View File

@ -205,7 +205,7 @@ public class TileMap extends MapActivity implements MapEventsReceiver {
break;
case R.id.menu_layer_grid:
mMapLayers.enableGridOverlay(!mMapLayers.isGridEnabled());
mMapLayers.enableGridOverlay(this, !mMapLayers.isGridEnabled());
mMap.updateMap(true);
break;

View File

@ -28,7 +28,7 @@ import java.net.URI;
public class AwtSvgBitmap extends AwtBitmap {
/**
* Default size is 20x20px (400px) at 240dpi.
* Default size is 20x20px (400px) at 160dpi.
*/
public static float DEFAULT_SIZE = 400f;
@ -79,7 +79,7 @@ public class AwtSvgBitmap extends AwtBitmap {
private static BufferedImage getResourceBitmapImpl(InputStream inputStream) throws IOException {
synchronized (SVGCache.getSVGUniverse()) {
return getResourceBitmap(inputStream, CanvasAdapter.dpi / 240, DEFAULT_SIZE, 0, 0, 100);
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, 0, 0, 100);
}
}

View File

@ -34,7 +34,7 @@ public class IosSvgBitmap extends IosBitmap {
private static final Logger log = LoggerFactory.getLogger(IosSvgBitmap.class);
/**
* Default size is 20x20px (400px) at 240dpi.
* Default size is 20x20px (400px) at 160dpi.
*/
public static float DEFAULT_SIZE = 400f;
@ -90,7 +90,7 @@ public class IosSvgBitmap extends IosBitmap {
}
private static UIImage getResourceBitmapImpl(InputStream inputStream) {
return getResourceBitmap(inputStream, CanvasAdapter.dpi / 240, DEFAULT_SIZE, 0, 0, 100);
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, 0, 0, 100);
}
public IosSvgBitmap(InputStream inputStream) throws IOException {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" base-text-scale="1.25"
map-background="#fffcfa" version="1" xmlns="http://opensciencemap.org/rendertheme"
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" map-background="#fffcfa"
version="1" xmlns="http://opensciencemap.org/rendertheme"
xsi:schemaLocation="http://opensciencemap.org/rendertheme https://raw.githubusercontent.com/mapsforge/vtm/master/resources/rendertheme.xsd">
<stylemenu defaultlang="en" defaultvalue="1" id="menu">

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" base-text-scale="1.25"
map-background="#fffcfa" version="1" xmlns="http://opensciencemap.org/rendertheme"
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" map-background="#fffcfa"
version="1" xmlns="http://opensciencemap.org/rendertheme"
xsi:schemaLocation="http://opensciencemap.org/rendertheme https://raw.githubusercontent.com/mapsforge/vtm/master/resources/rendertheme.xsd">
<!-- base style for fixed width lines -->
@ -1035,13 +1035,13 @@
<m k="railway">
<m v="station" zoom-min="14">
<symbol src="assets:symbols/transport/train_station.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
<m v="halt|tram_stop">
<symbol src="assets:symbols/transport/train_station2.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
<m v="level_crossing">

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" base-text-scale="1.25"
map-background="#fffcfa" version="1" xmlns="http://opensciencemap.org/rendertheme"
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" map-background="#fffcfa"
version="1" xmlns="http://opensciencemap.org/rendertheme"
xsi:schemaLocation="http://opensciencemap.org/rendertheme https://raw.githubusercontent.com/mapsforge/vtm/master/resources/rendertheme.xsd">
<!-- base style for fixed width lines -->
@ -1035,13 +1035,13 @@
<m k="railway">
<m v="station" zoom-min="14">
<symbol src="assets:symbols/transport/train_station.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
<m v="halt|tram_stop">
<symbol src="assets:symbols/transport/train_station2.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
<m v="level_crossing">

View File

@ -1204,12 +1204,12 @@
</m>
<m k="railway" v="station" zoom-min="14">
<symbol src="assets:symbols/transport/train_station.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
<m k="railway" v="halt|tram_stop" zoom-min="15">
<symbol src="assets:symbols/transport/train_station2.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
</m>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" base-text-scale="1.25"
map-background="#fffcfa" version="1" xmlns="http://opensciencemap.org/rendertheme"
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" map-background="#fffcfa"
version="1" xmlns="http://opensciencemap.org/rendertheme"
xsi:schemaLocation="http://opensciencemap.org/rendertheme https://raw.githubusercontent.com/mapsforge/vtm/master/resources/rendertheme.xsd">
<style-line id="trunk" stroke="#7fc97f" width="1.5" />
@ -1291,12 +1291,12 @@
</m>
<m k="railway" v="station" zoom-min="14">
<symbol src="assets:symbols/transport/train_station.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
<m k="railway" v="halt|tram_stop" zoom-min="15">
<symbol src="assets:symbols/transport/train_station2.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
</m>

View File

@ -1197,12 +1197,12 @@
</m>
<m k="railway" v="station" zoom-min="14">
<symbol src="assets:symbols/transport/train_station.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
<m k="railway" v="halt|tram_stop" zoom-min="15">
<symbol src="assets:symbols/transport/train_station2.svg" />
<caption style="bold" dy="-15" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
<caption style="bold" dy="-20" fill="#ec2d2d" k="name" size="14" stroke="#ffffff"
stroke-width="2.0" />
</m>
</m>

View File

@ -43,10 +43,15 @@ public abstract class CanvasAdapter {
*/
static CanvasAdapter g;
/**
* Default dpi.
*/
public static final float DEFAULT_DPI = 160;
/**
* The dpi.
*/
public static float dpi = 240;
public static float dpi = DEFAULT_DPI;
/**
* The scale.

View File

@ -1,6 +1,7 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Stephan Leuschner
* Copyright 2016 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -180,7 +181,7 @@ public class Animator {
float duration = 500;
float flingFactor = 240 / CanvasAdapter.dpi;
float flingFactor = CanvasAdapter.DEFAULT_DPI / CanvasAdapter.dpi;
mVelocity.x = velocityX * flingFactor;
mVelocity.y = velocityY * flingFactor;
mVelocity.x = clamp(mVelocity.x, xmin, xmax);

View File

@ -49,7 +49,7 @@ public class DefaultMapScaleBar extends MapScaleBar {
private final Paint paintScaleTextStroke;
public DefaultMapScaleBar(Map map) {
this(map, CanvasAdapter.dpi / 240);
this(map, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI);
}
public DefaultMapScaleBar(Map map, float scale) {

View File

@ -33,7 +33,7 @@ public class ThemeLoader {
public static IRenderTheme load(ThemeFile theme) throws ThemeException {
IRenderTheme t = XmlThemeBuilder.read(theme);
if (t != null)
t.scaleTextSize(CanvasAdapter.textScale + (CanvasAdapter.dpi / 240 - 1) * 0.5f);
t.scaleTextSize(CanvasAdapter.textScale + (CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI - 1));
return t;
}
}

View File

@ -134,7 +134,7 @@ public class XmlThemeBuilder extends DefaultHandler {
private final ThemeFile mTheme;
private RenderTheme mRenderTheme;
private final float mScale;
private final float mScale, mScale2;
private Set<String> mCategories;
private XmlRenderThemeStyleLayer mCurrentLayer;
@ -142,7 +142,8 @@ public class XmlThemeBuilder extends DefaultHandler {
public XmlThemeBuilder(ThemeFile theme) {
mTheme = theme;
mScale = CanvasAdapter.scale + (CanvasAdapter.dpi / 240 - 1) * 0.5f;
mScale = CanvasAdapter.scale + (CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI - 1);
mScale2 = CanvasAdapter.scale + (CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI - 1) * 0.5f;
}
@Override
@ -479,7 +480,7 @@ public class XmlThemeBuilder extends DefaultHandler {
b.color(value);
else if ("width".equals(name) || "stroke-width".equals(name)) {
b.strokeWidth = parseFloat(value) * mScale;
b.strokeWidth = parseFloat(value) * mScale2;
if (line == null) {
if (!isOutline)
validateNonNegative("width", b.strokeWidth);
@ -496,7 +497,7 @@ public class XmlThemeBuilder extends DefaultHandler {
b.fixed = parseBoolean(value);
else if ("stipple".equals(name))
b.stipple = Math.round(parseInt(value) * mScale);
b.stipple = Math.round(parseInt(value) * mScale2);
else if ("stipple-stroke".equals(name))
b.stippleColor(value);
@ -583,7 +584,7 @@ public class XmlThemeBuilder extends DefaultHandler {
else if ("stroke-width".equals(name)) {
float strokeWidth = Float.parseFloat(value);
validateNonNegative("stroke-width", strokeWidth);
b.strokeWidth = strokeWidth * mScale;
b.strokeWidth = strokeWidth * mScale2;
} else if ("fade".equals(name))
b.fadeScale = Integer.parseInt(value);
@ -856,7 +857,7 @@ public class XmlThemeBuilder extends DefaultHandler {
b.strokeColor = Color.parseColor(value);
else if ("stroke-width".equals(name))
b.strokeWidth = Float.parseFloat(value) * mScale;
b.strokeWidth = Float.parseFloat(value) * mScale2;
else if ("caption".equals(name))
b.caption = Boolean.parseBoolean(value);
@ -869,7 +870,7 @@ public class XmlThemeBuilder extends DefaultHandler {
else if ("dy".equals(name))
// NB: minus..
b.dy = -Float.parseFloat(value) * CanvasAdapter.dpi / 160;
b.dy = -Float.parseFloat(value) * mScale;
else if ("symbol".equals(name)) {
String lowValue = value.toLowerCase(Locale.ENGLISH);
@ -911,7 +912,7 @@ public class XmlThemeBuilder extends DefaultHandler {
String value = attributes.getValue(i);
if ("r".equals(name) || "radius".equals(name))
radius = Float.parseFloat(value) * mScale;
radius = Float.parseFloat(value) * mScale2;
else if ("cat".equals(name))
cat = value;
@ -926,7 +927,7 @@ public class XmlThemeBuilder extends DefaultHandler {
stroke = Color.parseColor(value);
else if ("stroke-width".equals(name))
strokeWidth = Float.parseFloat(value) * mScale;
strokeWidth = Float.parseFloat(value) * mScale2;
else
logUnknownAttribute(elementName, name, value, i);