Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f2f80d9374
11 changed files with 142 additions and 95 deletions
|
@ -137,7 +137,7 @@ public class GeocodingUtilities {
|
|||
}
|
||||
|
||||
|
||||
public List<GeocodingResult> reverseGeocodingSearch(RoutingContext ctx, double lat, double lon) throws IOException {
|
||||
public List<GeocodingResult> reverseGeocodingSearch(RoutingContext ctx, double lat, double lon, boolean allowEmptyNames) throws IOException {
|
||||
RoutePlannerFrontEnd rp = new RoutePlannerFrontEnd(false);
|
||||
List<GeocodingResult> lst = new ArrayList<GeocodingUtilities.GeocodingResult>();
|
||||
List<RouteSegmentPoint> listR = new ArrayList<BinaryRoutePlanner.RouteSegmentPoint>();
|
||||
|
@ -151,14 +151,14 @@ public class GeocodingUtilities {
|
|||
continue;
|
||||
}
|
||||
// System.out.println(road.toString() + " " + Math.sqrt(p.distSquare));
|
||||
boolean emptyName = Algorithms.isEmpty(road.getName()) && Algorithms.isEmpty(road.getRef("", false, true));
|
||||
if (!emptyName) {
|
||||
String name = Algorithms.isEmpty(road.getName()) ? road.getRef("", false, true) : road.getName();
|
||||
if (allowEmptyNames || !Algorithms.isEmpty(name)) {
|
||||
if (distSquare == 0 || distSquare > p.distSquare) {
|
||||
distSquare = p.distSquare;
|
||||
}
|
||||
GeocodingResult sr = new GeocodingResult();
|
||||
sr.searchPoint = new LatLon(lat, lon);
|
||||
sr.streetName = Algorithms.isEmpty(road.getName()) ? road.getRef("", false, true) : road.getName();
|
||||
sr.streetName = name == null ? "" : name;
|
||||
sr.point = p;
|
||||
sr.connectionPoint = new LatLon(MapUtils.get31LatitudeY(p.preciseY), MapUtils.get31LongitudeX(p.preciseX));
|
||||
sr.regionFP = road.region.getFilePointer();
|
||||
|
|
|
@ -93,7 +93,7 @@ public class OsmandRegions {
|
|||
}
|
||||
|
||||
|
||||
public void prepareFile(String fileName) throws IOException {
|
||||
public BinaryMapIndexReader prepareFile(String fileName) throws IOException {
|
||||
reader = new BinaryMapIndexReader(new RandomAccessFile(fileName, "r"), new File(fileName));
|
||||
// final Collator clt = OsmAndCollator.primaryCollator();
|
||||
final Map<String, String> parentRelations = new LinkedHashMap<String, String>();
|
||||
|
@ -138,6 +138,7 @@ public class OsmandRegions {
|
|||
}
|
||||
}
|
||||
structureWorldRegions(new ArrayList<WorldRegion>(fullNamesToRegionData.values()));
|
||||
return reader;
|
||||
}
|
||||
|
||||
public boolean containsCountry(String name) {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="shared_string_road">Road</string>
|
||||
<string name="show_map">Show map</string>
|
||||
<string name="route_is_calculated">Route is calculated</string>
|
||||
<string name="round_trip">Round trip</string>
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
|
@ -21,7 +19,12 @@ import net.osmand.router.RoutePlannerFrontEnd;
|
|||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.router.RoutingContext;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class CurrentPositionHelper {
|
||||
|
||||
|
@ -43,12 +46,13 @@ public class CurrentPositionHelper {
|
|||
return lastAskedLocation;
|
||||
}
|
||||
|
||||
public boolean getRouteSegment(Location loc, ResultMatcher<RouteDataObject> result) {
|
||||
return scheduleRouteSegmentFind(loc, false, null, result);
|
||||
public boolean getRouteSegment(Location loc, @Nullable ApplicationMode appMode,
|
||||
ResultMatcher<RouteDataObject> result) {
|
||||
return scheduleRouteSegmentFind(loc, false, true, null, result, appMode);
|
||||
}
|
||||
|
||||
public boolean getGeocodingResult(Location loc, ResultMatcher<GeocodingResult> result) {
|
||||
return scheduleRouteSegmentFind(loc, false, result, null);
|
||||
return scheduleRouteSegmentFind(loc, false, false, result, null, null);
|
||||
}
|
||||
|
||||
public RouteDataObject getLastKnownRouteSegment(Location loc) {
|
||||
|
@ -61,12 +65,12 @@ public class CurrentPositionHelper {
|
|||
return r;
|
||||
}
|
||||
if (r == null) {
|
||||
scheduleRouteSegmentFind(loc, true, null, null);
|
||||
scheduleRouteSegmentFind(loc, true, false, null, null, null);
|
||||
return null;
|
||||
}
|
||||
double d = getOrthogonalDistance(r, loc);
|
||||
if (d > 15) {
|
||||
scheduleRouteSegmentFind(loc, true, null, null);
|
||||
scheduleRouteSegmentFind(loc, true, false, null, null, null);
|
||||
}
|
||||
if (d < 70) {
|
||||
return r;
|
||||
|
@ -76,14 +80,19 @@ public class CurrentPositionHelper {
|
|||
|
||||
|
||||
///////////////////////// PRIVATE IMPLEMENTATION //////////////////////////
|
||||
private boolean scheduleRouteSegmentFind(final Location loc, final boolean storeFound, final ResultMatcher<GeocodingResult> geoCoding, final ResultMatcher<RouteDataObject> result) {
|
||||
private boolean scheduleRouteSegmentFind(final Location loc,
|
||||
final boolean storeFound,
|
||||
final boolean allowEmptyNames,
|
||||
@Nullable final ResultMatcher<GeocodingResult> geoCoding,
|
||||
@Nullable final ResultMatcher<RouteDataObject> result,
|
||||
@Nullable final ApplicationMode appMode) {
|
||||
boolean res = false;
|
||||
if (loc != null) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
try {
|
||||
processGeocoding(loc, geoCoding, storeFound, result);
|
||||
processGeocoding(loc, geoCoding, storeFound, allowEmptyNames, result, appMode);
|
||||
} catch (Exception e) {
|
||||
log.error("Error processing geocoding", e);
|
||||
e.printStackTrace();
|
||||
|
@ -96,8 +105,9 @@ public class CurrentPositionHelper {
|
|||
return res;
|
||||
}
|
||||
|
||||
private void initCtx(OsmandApplication app, List<BinaryMapReaderResource> checkReaders) {
|
||||
am = app.getSettings().getApplicationMode();
|
||||
private void initCtx(OsmandApplication app, List<BinaryMapReaderResource> checkReaders,
|
||||
@NonNull ApplicationMode appMode) {
|
||||
am = appMode;
|
||||
String p ;
|
||||
if (am.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
|
||||
p = GeneralRouterProfile.BICYCLE.name().toLowerCase();
|
||||
|
@ -129,9 +139,15 @@ public class CurrentPositionHelper {
|
|||
}
|
||||
|
||||
// single synchronized method
|
||||
private synchronized void processGeocoding(Location loc, ResultMatcher<GeocodingResult> geoCoding, boolean storeFound, final ResultMatcher<RouteDataObject> result) throws IOException {
|
||||
private synchronized void processGeocoding(@NonNull Location loc,
|
||||
@Nullable ResultMatcher<GeocodingResult> geoCoding,
|
||||
boolean storeFound,
|
||||
boolean allowEmptyNames,
|
||||
@Nullable final ResultMatcher<RouteDataObject> result,
|
||||
@Nullable ApplicationMode appMode) throws IOException {
|
||||
|
||||
final List<GeocodingResult> gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude(),
|
||||
geoCoding != null);
|
||||
geoCoding != null, allowEmptyNames, appMode);
|
||||
if (storeFound) {
|
||||
lastAskedLocation = loc;
|
||||
lastFound = gr == null || gr.isEmpty() ? null : gr.get(0).point.getRoad();
|
||||
|
@ -146,17 +162,25 @@ public class CurrentPositionHelper {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
private List<GeocodingResult> runUpdateInThread(double lat, double lon, boolean geocoding) throws IOException {
|
||||
|
||||
@Nullable
|
||||
private List<GeocodingResult> runUpdateInThread(double lat, double lon,
|
||||
boolean geocoding,
|
||||
boolean allowEmptyNames,
|
||||
@Nullable ApplicationMode appMode) throws IOException {
|
||||
|
||||
List<BinaryMapReaderResource> checkReaders = checkReaders(lat, lon, usedReaders);
|
||||
if (ctx == null || am != app.getSettings().getApplicationMode() || checkReaders != usedReaders) {
|
||||
initCtx(app, checkReaders);
|
||||
if (appMode == null) {
|
||||
appMode = app.getSettings().getApplicationMode();
|
||||
}
|
||||
if (ctx == null || am != appMode || checkReaders != usedReaders) {
|
||||
initCtx(app, checkReaders, appMode);
|
||||
if (ctx == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return new GeocodingUtilities().reverseGeocodingSearch(geocoding ? defCtx : ctx, lat, lon);
|
||||
return new GeocodingUtilities().reverseGeocodingSearch(geocoding ? defCtx : ctx, lat, lon, allowEmptyNames);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
|
|
@ -859,8 +859,9 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
return currentPositionHelper.getLastKnownRouteSegment(getLastKnownLocation());
|
||||
}
|
||||
|
||||
public boolean getRouteSegment(net.osmand.Location loc, ResultMatcher<RouteDataObject> result) {
|
||||
return currentPositionHelper.getRouteSegment(loc, result);
|
||||
public boolean getRouteSegment(net.osmand.Location loc, @Nullable ApplicationMode appMode,
|
||||
ResultMatcher<RouteDataObject> result) {
|
||||
return currentPositionHelper.getRouteSegment(loc, appMode, result);
|
||||
}
|
||||
|
||||
public boolean getGeocodingResult(net.osmand.Location loc, ResultMatcher<GeocodingResult> result) {
|
||||
|
|
|
@ -758,7 +758,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
return lang;
|
||||
}
|
||||
|
||||
public RoutingConfiguration.Builder getDefaultRoutingConfig() {
|
||||
public synchronized RoutingConfiguration.Builder getDefaultRoutingConfig() {
|
||||
if(defaultRoutingConfig == null) {
|
||||
defaultRoutingConfig = appInitializer.getLazyDefaultRoutingConfig();
|
||||
}
|
||||
|
|
|
@ -403,14 +403,24 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
@Override
|
||||
public void updateProgress(int progress) {
|
||||
if (findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE) {
|
||||
pbExtView.setVisibility(View.GONE);
|
||||
pb.setVisibility(View.VISIBLE);
|
||||
if (pbExtView.getVisibility() == View.VISIBLE) {
|
||||
pbExtView.setVisibility(View.GONE);
|
||||
}
|
||||
if (pb.getVisibility() == View.GONE) {
|
||||
pb.setVisibility(View.VISIBLE);
|
||||
}
|
||||
pb.setProgress(progress);
|
||||
pb.invalidate();
|
||||
pb.requestLayout();
|
||||
} else {
|
||||
pb.setVisibility(View.GONE);
|
||||
pbExtView.setVisibility(View.VISIBLE);
|
||||
if (pb.getVisibility() == View.VISIBLE) {
|
||||
pb.setVisibility(View.GONE);
|
||||
}
|
||||
if (pbExtView.getVisibility() == View.GONE) {
|
||||
pbExtView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
pbExt.setProgress(progress);
|
||||
pbExt.invalidate();
|
||||
pbExt.requestLayout();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ import android.widget.ImageButton;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -25,15 +27,14 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
|||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.AnimateDraggingMapThread;
|
||||
import net.osmand.plus.views.ContextMenuLayer;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.router.RoutingConfiguration.Builder;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AvoidSpecificRoads {
|
||||
private List<RouteDataObject> missingRoads;
|
||||
private List<RouteDataObject> impassableRoads;
|
||||
private OsmandApplication app;
|
||||
|
||||
public AvoidSpecificRoads(OsmandApplication app) {
|
||||
|
@ -47,24 +48,23 @@ public class AvoidSpecificRoads {
|
|||
}
|
||||
}
|
||||
|
||||
public List<RouteDataObject> getMissingRoads() {
|
||||
if (missingRoads == null) {
|
||||
missingRoads = app.getDefaultRoutingConfig().getImpassableRoads();
|
||||
private List<RouteDataObject> getImpassableRoads() {
|
||||
if (impassableRoads == null) {
|
||||
impassableRoads = app.getDefaultRoutingConfig().getImpassableRoads();
|
||||
}
|
||||
return missingRoads;
|
||||
return impassableRoads;
|
||||
}
|
||||
|
||||
|
||||
public ArrayAdapter<RouteDataObject> createAdapter(final MapActivity ctx) {
|
||||
private ArrayAdapter<RouteDataObject> createAdapter(final MapActivity ctx) {
|
||||
final ArrayList<RouteDataObject> points = new ArrayList<>();
|
||||
points.addAll(getMissingRoads());
|
||||
points.addAll(getImpassableRoads());
|
||||
final LatLon mapLocation = ctx.getMapLocation();
|
||||
return new ArrayAdapter<RouteDataObject>(ctx,
|
||||
R.layout.waypoint_reached, R.id.title, points) {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
// User super class to create the View
|
||||
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if (v == null || v.findViewById(R.id.info_close) == null) {
|
||||
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, parent, false);
|
||||
|
@ -107,24 +107,26 @@ public class AvoidSpecificRoads {
|
|||
|
||||
|
||||
protected String getText(RouteDataObject obj) {
|
||||
return RoutingHelper.formatStreetName(obj.getName(app.getSettings().MAP_PREFERRED_LOCALE.get(),
|
||||
app.getSettings().MAP_TRANSLITERATE_NAMES.get()),
|
||||
obj.getRef(app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get(), true),
|
||||
obj.getDestinationName(app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get(), true),
|
||||
String name = RoutingHelper.formatStreetName(obj.getName(app.getSettings().MAP_PREFERRED_LOCALE.get(),
|
||||
app.getSettings().MAP_TRANSLITERATE_NAMES.get()),
|
||||
obj.getRef(app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get(), true),
|
||||
obj.getDestinationName(app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get(), true),
|
||||
app.getString(R.string.towards));
|
||||
|
||||
return Algorithms.isEmpty(name) ? app.getString(R.string.shared_string_road) : name;
|
||||
}
|
||||
|
||||
public void showDialog(@NonNull final MapActivity mapActivity) {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
|
||||
bld.setTitle(R.string.impassable_road);
|
||||
if (getMissingRoads().size() == 0) {
|
||||
if (getImpassableRoads().size() == 0) {
|
||||
bld.setMessage(R.string.avoid_roads_msg);
|
||||
} else {
|
||||
final ArrayAdapter<?> listAdapter = createAdapter(mapActivity);
|
||||
bld.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
RouteDataObject obj = getMissingRoads().get(which);
|
||||
RouteDataObject obj = getImpassableRoads().get(which);
|
||||
double lat = MapUtils.get31LatitudeY(obj.getPoint31YTile(0));
|
||||
double lon = MapUtils.get31LongitudeX(obj.getPoint31XTile(0));
|
||||
showOnMap(mapActivity, lat, lon, getText(obj), dialog);
|
||||
|
@ -144,7 +146,7 @@ public class AvoidSpecificRoads {
|
|||
}
|
||||
|
||||
|
||||
protected void selectFromMap(final MapActivity mapActivity) {
|
||||
private void selectFromMap(final MapActivity mapActivity) {
|
||||
ContextMenuLayer cm = mapActivity.getMapLayers().getContextMenuLayer();
|
||||
cm.setSelectOnMap(new CallbackWithObject<LatLon>() {
|
||||
|
||||
|
@ -165,7 +167,9 @@ public class AvoidSpecificRoads {
|
|||
final Location ll = new Location("");
|
||||
ll.setLatitude(loc.getLatitude());
|
||||
ll.setLongitude(loc.getLongitude());
|
||||
app.getLocationProvider().getRouteSegment(ll, new ResultMatcher<RouteDataObject>() {
|
||||
ApplicationMode appMode = app.getRoutingHelper().getAppMode();
|
||||
|
||||
app.getLocationProvider().getRouteSegment(ll, appMode, new ResultMatcher<RouteDataObject>() {
|
||||
|
||||
@Override
|
||||
public boolean publish(RouteDataObject object) {
|
||||
|
@ -207,7 +211,9 @@ public class AvoidSpecificRoads {
|
|||
final Location ll = new Location("");
|
||||
ll.setLatitude(loc.getLatitude());
|
||||
ll.setLongitude(loc.getLongitude());
|
||||
app.getLocationProvider().getRouteSegment(ll, new ResultMatcher<RouteDataObject>() {
|
||||
ApplicationMode appMode = app.getRoutingHelper().getAppMode();
|
||||
|
||||
app.getLocationProvider().getRouteSegment(ll, appMode, new ResultMatcher<RouteDataObject>() {
|
||||
|
||||
@Override
|
||||
public boolean publish(RouteDataObject object) {
|
||||
|
@ -239,9 +245,9 @@ public class AvoidSpecificRoads {
|
|||
boolean showDialog,
|
||||
@Nullable MapActivity activity,
|
||||
@NonNull LatLon loc) {
|
||||
if(!app.getDefaultRoutingConfig().addImpassableRoad(object, ll)) {
|
||||
if (!app.getDefaultRoutingConfig().addImpassableRoad(object, ll)) {
|
||||
LatLon location = getLocation(object);
|
||||
if(location != null) {
|
||||
if (location != null) {
|
||||
app.getSettings().removeImpassableRoad(getLocation(object));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -952,14 +952,14 @@ public class RoutingHelper {
|
|||
}
|
||||
|
||||
public void startRouteCalculationThread(RouteCalculationParams params, boolean paramsChanged, boolean updateProgress) {
|
||||
if (updateProgress) {
|
||||
updateProgress(params);
|
||||
}
|
||||
synchronized (this) {
|
||||
final Thread prevRunningJob = currentRunningJob;
|
||||
RouteRecalculationThread newThread = new RouteRecalculationThread(
|
||||
"Calculating route", params, paramsChanged); //$NON-NLS-1$
|
||||
currentRunningJob = newThread;
|
||||
if (updateProgress) {
|
||||
updateProgress(params);
|
||||
}
|
||||
if (prevRunningJob != null) {
|
||||
newThread.setWaitPrevJob(prevRunningJob);
|
||||
}
|
||||
|
@ -974,7 +974,7 @@ public class RoutingHelper {
|
|||
} else {
|
||||
progressRoute = this.progressRoute;
|
||||
}
|
||||
if(progressRoute != null ) {
|
||||
if (progressRoute != null ) {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -986,6 +986,8 @@ public class RoutingHelper {
|
|||
if (all > 0) {
|
||||
int t = (int) Math.min(p * p / (all * all) * 100f, 99);
|
||||
progressRoute.updateProgress(t);
|
||||
} else {
|
||||
progressRoute.updateProgress(0);
|
||||
}
|
||||
Thread t = currentRunningJob;
|
||||
if(t instanceof RouteRecalculationThread && ((RouteRecalculationThread) t).params != params) {
|
||||
|
|
|
@ -34,15 +34,14 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
private static final int startZoom = 10;
|
||||
private final MapActivity activity;
|
||||
private Bitmap roadWorkIcon;
|
||||
private OsmandMapTileView view;
|
||||
private Paint paint;
|
||||
private Map<Long, Location> missingRoadLocations;
|
||||
private List<RouteDataObject> missingRoads;
|
||||
private Map<Long, Location> impassableRoadLocations;
|
||||
private List<RouteDataObject> impassableRoads;
|
||||
private RoutingHelper routingHelper;
|
||||
|
||||
private ContextMenuLayer contextMenuLayer;
|
||||
|
||||
private Set<PreservedRoadDataObject> mPreservedRoadDataObjects;
|
||||
private Set<StoredRoadDataObject> storedRoadDataObjects;
|
||||
|
||||
public ImpassableRoadsLayer(MapActivity activity) {
|
||||
this.activity = activity;
|
||||
|
@ -50,7 +49,6 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
roadWorkIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_pin_avoid_road);
|
||||
paint = new Paint();
|
||||
routingHelper = activity.getRoutingHelper();
|
||||
|
@ -58,9 +56,9 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
||||
|
||||
List<LatLon> impassibleRoads = activity.getMyApplication().getSettings().getImpassableRoadPoints();
|
||||
mPreservedRoadDataObjects = new HashSet<>(impassibleRoads.size());
|
||||
storedRoadDataObjects = new HashSet<>(impassibleRoads.size());
|
||||
for (LatLon impassibleRoad : impassibleRoads) {
|
||||
mPreservedRoadDataObjects.add(new PreservedRoadDataObject(impassibleRoad));
|
||||
storedRoadDataObjects.add(new StoredRoadDataObject(impassibleRoad));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,21 +73,25 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
for (long id : getMissingRoadLocations().keySet()) {
|
||||
if(contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
|
||||
for (long id : getImpassableRoadLocations().keySet()) {
|
||||
if (contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
|
||||
RouteDataObject object = (RouteDataObject) contextMenuLayer.getMoveableObject();
|
||||
if (object.id == id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Location location = getMissingRoadLocations().get(id);
|
||||
Location location = getImpassableRoadLocations().get(id);
|
||||
final double latitude = location.getLatitude();
|
||||
final double longitude = location.getLongitude();
|
||||
drawPoint(canvas, tileBox, latitude, longitude);
|
||||
if (tileBox.containsLatLon(latitude, longitude)) {
|
||||
drawPoint(canvas, tileBox, latitude, longitude);
|
||||
}
|
||||
}
|
||||
for (PreservedRoadDataObject preservedRoadDataObject : mPreservedRoadDataObjects) {
|
||||
final LatLon latLon = preservedRoadDataObject.getLatLon();
|
||||
drawPoint(canvas, tileBox, latLon.getLatitude(), latLon.getLongitude());
|
||||
for (StoredRoadDataObject storedRoadDataObject : storedRoadDataObjects) {
|
||||
final LatLon latLon = storedRoadDataObject.getLatLon();
|
||||
if (tileBox.containsLatLon(latLon)) {
|
||||
drawPoint(canvas, tileBox, latLon.getLatitude(), latLon.getLongitude());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,18 +108,18 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
canvas.drawBitmap(roadWorkIcon, left, top, paint);
|
||||
}
|
||||
|
||||
public Map<Long, Location> getMissingRoadLocations() {
|
||||
if (missingRoadLocations == null) {
|
||||
missingRoadLocations = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations();
|
||||
private Map<Long, Location> getImpassableRoadLocations() {
|
||||
if (impassableRoadLocations == null) {
|
||||
impassableRoadLocations = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations();
|
||||
}
|
||||
return missingRoadLocations;
|
||||
return impassableRoadLocations;
|
||||
}
|
||||
|
||||
public List<RouteDataObject> getMissingRoads() {
|
||||
if (missingRoads == null) {
|
||||
missingRoads = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoads();
|
||||
private List<RouteDataObject> getImpassableRoads() {
|
||||
if (impassableRoads == null) {
|
||||
impassableRoads = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoads();
|
||||
}
|
||||
return missingRoads;
|
||||
return impassableRoads;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,7 +132,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
return true;
|
||||
}
|
||||
|
||||
public int getRadiusPoi(RotatedTileBox tb) {
|
||||
private int getRadiusPoi(RotatedTileBox tb) {
|
||||
int r;
|
||||
if (tb.getZoom() < startZoom) {
|
||||
r = 0;
|
||||
|
@ -167,8 +169,8 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
int compare = getRadiusPoi(tileBox);
|
||||
int radius = compare * 3 / 2;
|
||||
|
||||
for (RouteDataObject road : getMissingRoads()) {
|
||||
Location location = getMissingRoadLocations().get(road.getId());
|
||||
for (RouteDataObject road : getImpassableRoads()) {
|
||||
Location location = getImpassableRoadLocations().get(road.getId());
|
||||
if (location != null) {
|
||||
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
|
@ -179,9 +181,9 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!mPreservedRoadDataObjects.isEmpty()) {
|
||||
if (!storedRoadDataObjects.isEmpty()) {
|
||||
activity.getMyApplication().getAvoidSpecificRoads().initPreservedData();
|
||||
mPreservedRoadDataObjects.clear();
|
||||
storedRoadDataObjects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,7 +191,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
public LatLon getObjectLocation(Object o) {
|
||||
if (o instanceof RouteDataObject) {
|
||||
RouteDataObject route = (RouteDataObject) o;
|
||||
Location location = missingRoadLocations.get(route.getId());
|
||||
Location location = impassableRoadLocations.get(route.getId());
|
||||
return new LatLon(location.getLatitude(), location.getLongitude());
|
||||
}
|
||||
return null;
|
||||
|
@ -255,15 +257,15 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
}
|
||||
}
|
||||
|
||||
private static class PreservedRoadDataObject {
|
||||
private final LatLon mLatLon;
|
||||
private static class StoredRoadDataObject {
|
||||
private final LatLon latLon;
|
||||
|
||||
private PreservedRoadDataObject(LatLon latLon) {
|
||||
this.mLatLon = latLon;
|
||||
private StoredRoadDataObject(LatLon latLon) {
|
||||
this.latLon = latLon;
|
||||
}
|
||||
|
||||
public LatLon getLatLon() {
|
||||
return mLatLon;
|
||||
return latLon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ public class CurrentPositionHelper {
|
|||
}
|
||||
}
|
||||
try {
|
||||
return new GeocodingUtilities().reverseGeocodingSearch(defCtx, lat, lon);
|
||||
return new GeocodingUtilities().reverseGeocodingSearch(defCtx, lat, lon, false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue