Fix rendering make view distance

This commit is contained in:
vshcherb 2013-10-07 10:49:06 +03:00
parent fccd11ae15
commit 8b543181b2
11 changed files with 62 additions and 43 deletions

View file

@ -1,5 +1,8 @@
package net.osmand; package net.osmand;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRuleSearchRequest;
public class RenderingContext { public class RenderingContext {
static enum ShadowRenderingMode { static enum ShadowRenderingMode {
@ -57,6 +60,10 @@ public class RenderingContext {
return val * density; return val * density;
} }
public float getComplexValue(RenderingRuleSearchRequest req, RenderingRuleProperty prop, float defVal) {
return req.getFloatPropertyValue(prop, defVal) * density;
}
protected byte[] getIconRawData(String data) { protected byte[] getIconRawData(String data) {
return null; return null;
} }

View file

@ -344,11 +344,6 @@ public class RotatedTileBox {
calculateDerivedFields(); calculateDerivedFields();
} }
public QuadPoint getLeftTopTilePoint() {
checkTileRectangleCalculated();
return tileLT;
}
public LatLon getLeftTopLatLon() { public LatLon getLeftTopLatLon() {
checkTileRectangleCalculated(); checkTileRectangleCalculated();
return new LatLon(MapUtils.getLatitudeFromTile(zoom, tileLT.y), return new LatLon(MapUtils.getLatitudeFromTile(zoom, tileLT.y),

View file

@ -229,6 +229,14 @@ public class RenderingRuleSearchRequest {
return fvalues[property.getId()]; return fvalues[property.getId()];
} }
public float getFloatPropertyValue(RenderingRuleProperty property, float defVal) {
float f = fvalues[property.getId()];
if(f == 0) {
return defVal;
}
return f;
}
public String getColorStringPropertyValue(RenderingRuleProperty property) { public String getColorStringPropertyValue(RenderingRuleProperty property) {
return RenderingRuleProperty.colorToString(values[property.getId()]); return RenderingRuleProperty.colorToString(values[property.getId()]);
} }

View file

@ -175,13 +175,13 @@ public class RenderingRuleStorageProperties {
R_SHADOW_LEVEL = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(SHADOW_LEVEL)); R_SHADOW_LEVEL = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(SHADOW_LEVEL));
// text properties // text properties
R_TEXT_WRAP_WIDTH = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_WRAP_WIDTH)); R_TEXT_WRAP_WIDTH = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_WRAP_WIDTH));
R_TEXT_DY = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_DY)); R_TEXT_DY = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_DY));
R_TEXT_HALO_RADIUS = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_HALO_RADIUS)); R_TEXT_HALO_RADIUS = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_HALO_RADIUS));
R_TEXT_SIZE = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_SIZE)); R_TEXT_SIZE = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_SIZE));
R_TEXT_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_ORDER)); R_TEXT_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_ORDER));
R_ICON_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(ICON_ORDER)); R_ICON_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(ICON_ORDER));
R_TEXT_MIN_DISTANCE = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_MIN_DISTANCE)); R_TEXT_MIN_DISTANCE = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_MIN_DISTANCE));
R_TEXT_SHIELD = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(TEXT_SHIELD)); R_TEXT_SHIELD = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(TEXT_SHIELD));
@ -218,7 +218,7 @@ public class RenderingRuleStorageProperties {
R_SHADER = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(SHADER)); R_SHADER = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(SHADER));
R_SHADOW_COLOR = registerRuleInternal(RenderingRuleProperty.createOutputColorProperty(SHADOW_COLOR)); R_SHADOW_COLOR = registerRuleInternal(RenderingRuleProperty.createOutputColorProperty(SHADOW_COLOR));
R_SHADOW_RADIUS = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(SHADOW_RADIUS)); R_SHADOW_RADIUS = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(SHADOW_RADIUS));
} }
public RenderingRuleProperty get(String name) { public RenderingRuleProperty get(String name) {

View file

@ -12,6 +12,8 @@
<Preference android:title="@string/speak_title" android:summary="@string/speak_descr" android:key="speak_routing_alarms"/> <Preference android:title="@string/speak_title" android:summary="@string/speak_descr" android:key="speak_routing_alarms"/>
<Preference android:title="@string/avoid_in_routing_title" android:summary="@string/avoid_in_routing_descr" android:key="avoid_in_routing"/> <Preference android:title="@string/avoid_in_routing_title" android:summary="@string/avoid_in_routing_descr" android:key="avoid_in_routing"/>
<Preference android:title="@string/prefer_in_routing_title" android:summary="@string/prefer_in_routing_descr" android:key="prefer_in_routing"/> <Preference android:title="@string/prefer_in_routing_title" android:summary="@string/prefer_in_routing_descr" android:key="prefer_in_routing"/>
<ListPreference android:key="route_view_distance" android:title="@string/route_distance_settings"
android:summary="@string/route_distance_settings_descr"></ListPreference>
<CheckBoxPreference android:summary="@string/use_compass_navigation_descr" android:title="@string/use_compass_navigation" <CheckBoxPreference android:summary="@string/use_compass_navigation_descr" android:title="@string/use_compass_navigation"
android:key="use_compass_navigation"></CheckBoxPreference> android:key="use_compass_navigation"></CheckBoxPreference>
<CheckBoxPreference android:summary="@string/precise_routing_mode_descr" android:title="@string/precise_routing_mode" <CheckBoxPreference android:summary="@string/precise_routing_mode_descr" android:title="@string/precise_routing_mode"

View file

@ -654,14 +654,14 @@ public class OsmandSettings {
DAYNIGHT_MODE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, DayNightMode.DAY); DAYNIGHT_MODE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, DayNightMode.DAY);
} }
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<RouteService> ROUTER_SERVICE = public final OsmandPreference<RouteService> ROUTER_SERVICE =
new EnumIntPreference<RouteService>("router_service", RouteService.OSMAND, new EnumIntPreference<RouteService>("router_service", RouteService.OSMAND,
RouteService.values()).makeProfile(); RouteService.values()).makeProfile();
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<RouteViewDistance> ROUTE_VIEW_DISTANCE = public final OsmandPreference<RouteViewDistance> ROUTE_VIEW_DISTANCE =
new EnumIntPreference<RouteViewDistance>("router_service", RouteViewDistance.FAREST, new EnumIntPreference<RouteViewDistance>("route_view_distance", RouteViewDistance.FAREST,
RouteViewDistance.values()).makeProfile().cache(); RouteViewDistance.values()).makeProfile().cache();
public final CommonPreference<Boolean> SNAP_TO_ROAD = new BooleanPreference("snap_to_road", false).makeProfile().cache(); public final CommonPreference<Boolean> SNAP_TO_ROAD = new BooleanPreference("snap_to_road", false).makeProfile().cache();

View file

@ -8,6 +8,7 @@ import java.util.Set;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.OsmandSettings.RouteViewDistance;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -27,6 +28,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
private Preference showAlarms; private Preference showAlarms;
private Preference speakAlarms; private Preference speakAlarms;
private ListPreference routerServicePreference; private ListPreference routerServicePreference;
private ListPreference routeViewDistancePreference;
public static final String MORE_VALUE = "MORE_VALUE"; public static final String MORE_VALUE = "MORE_VALUE";
public SettingsNavigationActivity() { public SettingsNavigationActivity() {
@ -82,7 +84,15 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
registerListPreference(settings.ROUTER_SERVICE, screen, entries, RouteService.values()); registerListPreference(settings.ROUTER_SERVICE, screen, entries, RouteService.values());
routerServicePreference = (ListPreference) screen.findPreference(settings.ROUTER_SERVICE.getId()); routerServicePreference = (ListPreference) screen.findPreference(settings.ROUTER_SERVICE.getId());
routerServicePreference.setOnPreferenceChangeListener(this);
entries = new String[RouteViewDistance.values().length];
for(int i=0; i<entries.length; i++){
entries[i] = getString(RouteViewDistance.values()[i].name);
}
registerListPreference(settings.ROUTE_VIEW_DISTANCE, screen, entries, RouteViewDistance.values());
routeViewDistancePreference = (ListPreference) screen.findPreference(settings.ROUTE_VIEW_DISTANCE.getId());
routeViewDistancePreference.setOnPreferenceChangeListener(this);
avoidRouting = (Preference) screen.findPreference("avoid_in_routing"); avoidRouting = (Preference) screen.findPreference("avoid_in_routing");

View file

@ -30,7 +30,6 @@ import net.osmand.binary.BinaryMapIndexReader.MapIndex;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.QuadPoint;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback; import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
@ -61,9 +60,7 @@ import android.widget.Toast;
public class MapRenderRepositories { public class MapRenderRepositories {
// TimeLoadingMap = Rendering (%25) + Searching(%40) + Other
// It is needed to not draw object twice if user have map index that intersects by boundaries // It is needed to not draw object twice if user have map index that intersects by boundaries
// Takes 25% TimeLoadingMap (?) - Long.valueOf - 12, add - 10, contains - 3.
public static boolean checkForDuplicateObjectIds = true; public static boolean checkForDuplicateObjectIds = true;
@ -556,20 +553,22 @@ public class MapRenderRepositories {
currentRenderingContext.shadowRenderingMode = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE); currentRenderingContext.shadowRenderingMode = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE);
currentRenderingContext.shadowRenderingColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_SHADOW_COLOR); currentRenderingContext.shadowRenderingColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_SHADOW_COLOR);
} }
final QuadPoint lt = requestedBox.getLeftTopTilePoint(); // final QuadPoint lt = requestedBox.getLeftTopTilePoint();
currentRenderingContext.leftX = lt.x; LatLon lt = requestedBox.getLeftTopLatLon();
currentRenderingContext.topY = lt.y ; final float mapDensity = (float) Math.pow(2, requestedBox.getZoomScale());
final float tileDivisor = (float) MapUtils.getPowZoom(31 - requestedBox.getZoom() -
requestedBox.getZoomScale());
currentRenderingContext.leftX = MapUtils.get31TileNumberX(lt.getLongitude()) / tileDivisor;
currentRenderingContext.topY = MapUtils.get31TileNumberY(lt.getLatitude()) / tileDivisor;
currentRenderingContext.zoom = requestedBox.getZoom(); currentRenderingContext.zoom = requestedBox.getZoom();
currentRenderingContext.rotate = requestedBox.getRotate(); currentRenderingContext.rotate = requestedBox.getRotate();
final float mapDensity = (float) Math.pow(2, requestedBox.getZoomScale()); currentRenderingContext.width = requestedBox.getPixWidth();
currentRenderingContext.width = (int) (requestedBox.getPixWidth() / mapDensity); currentRenderingContext.height = requestedBox.getPixHeight();
currentRenderingContext.height = (int) (requestedBox.getPixHeight() / mapDensity);
currentRenderingContext.nightMode = nightMode; currentRenderingContext.nightMode = nightMode;
currentRenderingContext.useEnglishNames = prefs.USE_ENGLISH_NAMES.get(); currentRenderingContext.useEnglishNames = prefs.USE_ENGLISH_NAMES.get();
currentRenderingContext.setDensityValue(1.5f); currentRenderingContext.setDensityValue(mapDensity);
//currentRenderingContext.setDensityValue(renderer.getDensity() * prefs.MAP_ZOOM_SCALE_BY_DENSITY.get());
// init rendering context // init rendering context
currentRenderingContext.tileDivisor = (float) MapUtils.getPowZoom(31 - requestedBox.getZoom()); currentRenderingContext.tileDivisor = tileDivisor;
if (checkWhetherInterrupted()) { if (checkWhetherInterrupted()) {
return; return;
} }

View file

@ -40,7 +40,6 @@ import android.graphics.PathEffect;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.graphics.RectF;
import android.graphics.Shader; import android.graphics.Shader;
import android.graphics.Shader.TileMode; import android.graphics.Shader.TileMode;
import android.os.Handler; import android.os.Handler;
@ -535,7 +534,7 @@ public class OsmandRenderer {
p.setColorFilter(null); p.setColorFilter(null);
p.clearShadowLayer(); p.clearShadowLayer();
p.setStyle(Style.STROKE); p.setStyle(Style.STROKE);
p.setStrokeWidth(req.getFloatPropertyValue(rStrokeW)); p.setStrokeWidth(rc.getComplexValue(req, rStrokeW, 0));
String cap = req.getStringPropertyValue(rCap); String cap = req.getStringPropertyValue(rCap);
if(!Algorithms.isEmpty(cap)){ if(!Algorithms.isEmpty(cap)){
p.setStrokeCap(Cap.valueOf(cap.toUpperCase())); p.setStrokeCap(Cap.valueOf(cap.toUpperCase()));
@ -561,11 +560,11 @@ public class OsmandRenderer {
if(shadowColor == 0) { if(shadowColor == 0) {
shadowColor = rc.shadowRenderingColor; shadowColor = rc.shadowRenderingColor;
} }
int shadowLayer = req.getIntPropertyValue(req.ALL.R_SHADOW_RADIUS); int shadowRadius = (int) rc.getComplexValue(req, req.ALL.R_SHADOW_RADIUS, 0);
if (shadowColor == 0) { if (shadowColor == 0) {
shadowLayer = 0; shadowRadius = 0;
} }
p.setShadowLayer(shadowLayer, 0, 0, shadowColor); p.setShadowLayer(shadowRadius, 0, 0, shadowColor);
} }
} }

View file

@ -59,20 +59,20 @@ public class TextRenderer {
String shieldRes = null; String shieldRes = null;
int textOrder = 100; int textOrder = 100;
public void fillProperties(RenderingRuleSearchRequest render, float centerX, float centerY) { public void fillProperties(RenderingContext rc, RenderingRuleSearchRequest render, float centerX, float centerY) {
this.centerX = centerX; this.centerX = centerX;
this.centerY = centerY + render.getIntPropertyValue(render.ALL.R_TEXT_DY, 0);
// used only for draw on path where centerY doesn't play role // used only for draw on path where centerY doesn't play role
this.vOffset = render.getIntPropertyValue(render.ALL.R_TEXT_DY, 0); this.vOffset = (int) rc.getComplexValue(render, render.ALL.R_TEXT_DY, 0);
this.centerY = centerY + this.vOffset;
textColor = render.getIntPropertyValue(render.ALL.R_TEXT_COLOR); textColor = render.getIntPropertyValue(render.ALL.R_TEXT_COLOR);
if (textColor == 0) { if (textColor == 0) {
textColor = Color.BLACK; textColor = Color.BLACK;
} }
textSize = render.getIntPropertyValue(render.ALL.R_TEXT_SIZE); textSize = rc.getComplexValue(render, render.ALL.R_TEXT_SIZE, 0);
textShadow = render.getIntPropertyValue(render.ALL.R_TEXT_HALO_RADIUS, 0); textShadow = (int) rc.getComplexValue(render, render.ALL.R_TEXT_HALO_RADIUS, 0);
textWrap = render.getIntPropertyValue(render.ALL.R_TEXT_WRAP_WIDTH, 0); textWrap = (int) rc.getComplexValue(render, render.ALL.R_TEXT_WRAP_WIDTH, 0);
bold = render.getIntPropertyValue(render.ALL.R_TEXT_BOLD, 0) > 0; bold = render.getIntPropertyValue(render.ALL.R_TEXT_BOLD, 0) > 0;
minDistance = render.getIntPropertyValue(render.ALL.R_TEXT_MIN_DISTANCE, 0); minDistance = rc.getComplexValue(render, render.ALL.R_TEXT_MIN_DISTANCE, 0);
if (render.isSpecified(render.ALL.R_TEXT_SHIELD)) { if (render.isSpecified(render.ALL.R_TEXT_SHIELD)) {
shieldRes = render.getStringPropertyValue(render.ALL.R_TEXT_SHIELD); shieldRes = render.getStringPropertyValue(render.ALL.R_TEXT_SHIELD);
} }
@ -303,9 +303,9 @@ public class TextRenderer {
render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length()); render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length());
render.setStringFilter(render.ALL.R_NAME_TAG, tagName); render.setStringFilter(render.ALL.R_NAME_TAG, tagName);
if(render.search(RenderingRulesStorage.TEXT_RULES)){ if(render.search(RenderingRulesStorage.TEXT_RULES)){
if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){ if(render.getFloatPropertyValue(render.ALL.R_TEXT_SIZE) > 0){
final TextDrawInfo text = new TextDrawInfo(name); final TextDrawInfo text = new TextDrawInfo(name);
text.fillProperties(render, xMid, yMid); text.fillProperties(rc, render, xMid, yMid);
final String tagName2 = render.getStringPropertyValue(render.ALL.R_NAME_TAG2); final String tagName2 = render.getStringPropertyValue(render.ALL.R_NAME_TAG2);
if (!Algorithms.isEmpty(tagName2)) { if (!Algorithms.isEmpty(tagName2)) {
o.getObjectNames().forEachEntry(new TIntObjectProcedure<String>() { o.getObjectNames().forEachEntry(new TIntObjectProcedure<String>() {

View file

@ -369,15 +369,14 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
currentViewport.getCenterPixelY() != cy) { currentViewport.getCenterPixelY() != cy) {
currentViewport.setPixelDimensions(getWidth(), getHeight(), 0.5f, ratioy); currentViewport.setPixelDimensions(getWidth(), getHeight(), 0.5f, ratioy);
} }
// TODO high res
// (getSettings().USE_HIGH_RES_MAPS.get() ? 0 : 0.5f)
boolean nightMode = application.getDaynightHelper().isNightMode(); boolean nightMode = application.getDaynightHelper().isNightMode();
if (nightMode) { if (nightMode) {
canvas.drawARGB(255, 100, 100, 100); canvas.drawARGB(255, 100, 100, 100);
} else { } else {
canvas.drawARGB(255, 225, 225, 225); canvas.drawARGB(255, 225, 225, 225);
} }
drawOverMap(canvas, currentViewport, new DrawSettings(nightMode, updateVectorRendering), false); // make copy to avoid concurrency
drawOverMap(canvas, currentViewport.copy(), new DrawSettings(nightMode, updateVectorRendering), false);
} finally { } finally {
holder.unlockCanvasAndPost(canvas); holder.unlockCanvasAndPost(canvas);
} }