Impassable roads layer. Icons showing.
This commit is contained in:
parent
3aa63e40fc
commit
e9798b248d
5 changed files with 115 additions and 32 deletions
|
@ -1,6 +1,11 @@
|
|||
package net.osmand.router;
|
||||
|
||||
import gnu.trove.set.hash.TLongHashSet;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -14,12 +19,7 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import gnu.trove.set.hash.TLongHashSet;
|
||||
|
||||
public class GeneralRouter implements VehicleRouter {
|
||||
|
||||
|
@ -875,7 +875,7 @@ public class GeneralRouter implements VehicleRouter {
|
|||
|
||||
}
|
||||
|
||||
public void addImpassableRoads(TLongHashSet impassableRoads) {
|
||||
public void addImpassableRoads(Set<Long> impassableRoads) {
|
||||
if (impassableRoads != null && !impassableRoads.isEmpty()) {
|
||||
if (this.impassableRoads == null) {
|
||||
this.impassableRoads = new TLongHashSet();
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
package net.osmand.router;
|
||||
|
||||
import gnu.trove.set.hash.TLongHashSet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||
|
@ -20,6 +11,15 @@ import net.osmand.util.Algorithms;
|
|||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
public class RoutingConfiguration {
|
||||
|
||||
public static final int DEFAULT_MEMORY_LIMIT = 30;
|
||||
|
@ -55,12 +55,12 @@ public class RoutingConfiguration {
|
|||
private String defaultRouter = "";
|
||||
private Map<String, GeneralRouter> routers = new LinkedHashMap<String, GeneralRouter>();
|
||||
private Map<String, String> attributes = new LinkedHashMap<String, String>();
|
||||
private TLongHashSet impassableRoadIds = new TLongHashSet();
|
||||
private HashMap<Long, Location> impassableRoadLocations = new HashMap<>();
|
||||
private List<RouteDataObject> impassableRoads = new ArrayList<RouteDataObject>();
|
||||
|
||||
// Example
|
||||
// {
|
||||
// impassableRoadIds.add(23000069L);
|
||||
// impassableRoadLocations.add(23000069L);
|
||||
// }
|
||||
|
||||
public RoutingConfiguration build(String router, int memoryLimitMB) {
|
||||
|
@ -87,7 +87,7 @@ public class RoutingConfiguration {
|
|||
i.initialDirection = direction;
|
||||
i.recalculateDistance = parseSilentFloat(getAttribute(i.router, "recalculateDistanceHelp"), i.recalculateDistance) ;
|
||||
i.heuristicCoefficient = parseSilentFloat(getAttribute(i.router, "heuristicCoefficient"), i.heuristicCoefficient);
|
||||
i.router.addImpassableRoads(impassableRoadIds);
|
||||
i.router.addImpassableRoads(impassableRoadLocations.keySet());
|
||||
i.ZOOM_TO_LOAD_TILES = parseSilentInt(getAttribute(i.router, "zoomToLoadTiles"), i.ZOOM_TO_LOAD_TILES);
|
||||
int desirable = parseSilentInt(getAttribute(i.router, "memoryLimitInMB"), 0);
|
||||
if(desirable != 0) {
|
||||
|
@ -109,14 +109,14 @@ public class RoutingConfiguration {
|
|||
return impassableRoads;
|
||||
}
|
||||
|
||||
public TLongHashSet getImpassableRoadIds() {
|
||||
return impassableRoadIds;
|
||||
public Map<Long, Location> getImpassableRoadLocations() {
|
||||
return impassableRoadLocations;
|
||||
}
|
||||
|
||||
public void addImpassableRoad(RouteDataObject r) {
|
||||
if (!impassableRoadIds.contains(r.id)){
|
||||
impassableRoadIds.add(r.id);
|
||||
impassableRoads.add(r);
|
||||
public void addImpassableRoad(RouteDataObject route, Location location) {
|
||||
if (!impassableRoadLocations.containsKey(route.id)){
|
||||
impassableRoadLocations.put(route.id, location);
|
||||
impassableRoads.add(route);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ public class RoutingConfiguration {
|
|||
}
|
||||
|
||||
public void removeImpassableRoad(RouteDataObject obj) {
|
||||
impassableRoadIds.remove(obj.id);
|
||||
impassableRoadLocations.remove(obj.id);
|
||||
impassableRoads.remove(obj);
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import net.osmand.plus.views.ContextMenuLayer;
|
|||
import net.osmand.plus.views.DownloadedRegionsLayer;
|
||||
import net.osmand.plus.views.FavoritesLayer;
|
||||
import net.osmand.plus.views.GPXLayer;
|
||||
import net.osmand.plus.views.ImpassableRoadsLayer;
|
||||
import net.osmand.plus.views.MapControlsLayer;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.MapTextLayer;
|
||||
|
@ -71,6 +72,7 @@ public class MapActivityLayers {
|
|||
private TransportInfoLayer transportInfoLayer;
|
||||
private PointLocationLayer locationLayer;
|
||||
private PointNavigationLayer navigationLayer;
|
||||
private ImpassableRoadsLayer impassableRoadsLayer;
|
||||
private MapInfoLayer mapInfoLayer;
|
||||
private MapTextLayer mapTextLayer;
|
||||
private ContextMenuLayer contextMenuLayer;
|
||||
|
@ -79,7 +81,7 @@ public class MapActivityLayers {
|
|||
private MapWidgetRegistry mapWidgetRegistry;
|
||||
|
||||
private StateChangedListener<Integer> transparencyListener;
|
||||
|
||||
|
||||
public MapActivityLayers(MapActivity activity) {
|
||||
this.activity = activity;
|
||||
this.mapWidgetRegistry = new MapWidgetRegistry(activity.getMyApplication().getSettings());
|
||||
|
@ -141,6 +143,9 @@ public class MapActivityLayers {
|
|||
// 7. point navigation layer
|
||||
navigationLayer = new PointNavigationLayer(activity);
|
||||
mapView.addLayer(navigationLayer, 7);
|
||||
// 7.5 Impassible roads
|
||||
impassableRoadsLayer = new ImpassableRoadsLayer(activity);
|
||||
mapView.addLayer(impassableRoadsLayer, 7.5f);
|
||||
// 8. context menu layer
|
||||
contextMenuLayer = new ContextMenuLayer(activity);
|
||||
mapView.addLayer(contextMenuLayer, 8);
|
||||
|
@ -421,7 +426,11 @@ public class MapActivityLayers {
|
|||
public PointNavigationLayer getNavigationLayer() {
|
||||
return navigationLayer;
|
||||
}
|
||||
|
||||
|
||||
public ImpassableRoadsLayer getImpassableRoadsLayer() {
|
||||
return impassableRoadsLayer;
|
||||
}
|
||||
|
||||
public GPXLayer getGpxLayer() {
|
||||
return gpxLayer;
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ public class AvoidSpecificRoads {
|
|||
});
|
||||
}
|
||||
private void findRoad(final MapActivity activity, final LatLon loc) {
|
||||
Location ll = new Location("");
|
||||
final Location ll = new Location("");
|
||||
ll.setLatitude(loc.getLatitude());
|
||||
ll.setLongitude(loc.getLongitude());
|
||||
app.getLocationProvider().getRouteSegment(ll, new ResultMatcher<RouteDataObject>() {
|
||||
|
@ -154,7 +154,7 @@ public class AvoidSpecificRoads {
|
|||
if(object == null) {
|
||||
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
getBuilder().addImpassableRoad(object);
|
||||
getBuilder().addImpassableRoad(object, ll);
|
||||
RoutingHelper rh = app.getRoutingHelper();
|
||||
if(rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||
rh.recalculateRouteDueToSettingsChange();
|
||||
|
|
74
OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java
Normal file
74
OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java
Normal file
|
@ -0,0 +1,74 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Denis on
|
||||
* 20.03.2015.
|
||||
*/
|
||||
public class ImpassableRoadsLayer extends OsmandMapLayer {
|
||||
|
||||
private static final int startZoom = 10;
|
||||
private final MapActivity activity;
|
||||
private Bitmap roadWorkIcon;
|
||||
private OsmandMapTileView view;
|
||||
private Paint paint;
|
||||
private Map<Long, Location> missingRoads;
|
||||
|
||||
public ImpassableRoadsLayer(MapActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
roadWorkIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.ic_action_road_works_dark);
|
||||
paint = new Paint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
for (long id : getMissingRoads().keySet()) {
|
||||
Location location = getMissingRoads().get(id);
|
||||
float x = tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
float y = tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
float left = x - roadWorkIcon.getWidth() / 2;
|
||||
float top = y - roadWorkIcon.getHeight() / 2;
|
||||
canvas.drawBitmap(roadWorkIcon, left, top, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Long, Location> getMissingRoads() {
|
||||
if(missingRoads == null) {
|
||||
missingRoads = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations();
|
||||
}
|
||||
return missingRoads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drawInScreenPixels() {
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue