Impassable roads layer. Context menu implemented.
This commit is contained in:
parent
5362feabe1
commit
b8f918f34f
4 changed files with 159 additions and 10 deletions
|
@ -28,4 +28,5 @@
|
|||
<string name="hint_value">Value</string>
|
||||
<string name="clear_updates_proposition_message">"You can remove downloaded updates and free "</string>
|
||||
<string name="add_time_span">Add time span</string>
|
||||
<string name="road_blocked">Road blocked</string>
|
||||
</resources>
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -21,6 +22,7 @@ import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController;
|
|||
import net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController;
|
||||
|
@ -105,6 +107,9 @@ public abstract class MenuController extends BaseMenuController {
|
|||
} else if (pointDescription.isMyLocation()) {
|
||||
menuController = new MyLocationMenuController(app, mapActivity, pointDescription);
|
||||
}
|
||||
} else if (object instanceof RouteDataObject) {
|
||||
menuController = new ImpassibleRoadsMenuController(app, mapActivity,
|
||||
pointDescription, (RouteDataObject) object);
|
||||
}
|
||||
}
|
||||
if (menuController == null) {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package net.osmand.plus.mapcontextmenu.controllers;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
|
||||
public class ImpassibleRoadsMenuController extends MenuController {
|
||||
|
||||
private RouteDataObject route;
|
||||
|
||||
public ImpassibleRoadsMenuController(final OsmandApplication app, final MapActivity mapActivity,
|
||||
PointDescription pointDescription, RouteDataObject route) {
|
||||
super(new MenuBuilder(app), pointDescription, mapActivity);
|
||||
this.route = route;
|
||||
rightTitleButtonController = new TitleButtonController() {
|
||||
@Override
|
||||
public void buttonPressed() {
|
||||
app.getDefaultRoutingConfig().removeImpassableRoad(
|
||||
ImpassibleRoadsMenuController.this.route);
|
||||
RoutingHelper rh = app.getRoutingHelper();
|
||||
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||
rh.recalculateRouteDueToSettingsChange();
|
||||
}
|
||||
getMapActivity().getContextMenu().close();
|
||||
}
|
||||
};
|
||||
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete);
|
||||
rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setObject(Object object) {
|
||||
route = (RouteDataObject) object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeStr() {
|
||||
return getMapActivity().getString(R.string.road_blocked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getLeftIcon() {
|
||||
return getMapActivity().getResources().getDrawable(R.drawable.ic_action_road_works_dark);
|
||||
}
|
||||
}
|
|
@ -4,26 +4,32 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PointF;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.osmedit.OsmNotesPoint;
|
||||
import net.osmand.plus.osmedit.OsmPoint;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Denis on
|
||||
* 20.03.2015.
|
||||
*/
|
||||
public class ImpassableRoadsLayer extends OsmandMapLayer {
|
||||
public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
|
||||
|
||||
private static final int startZoom = 10;
|
||||
private final MapActivity activity;
|
||||
private Bitmap roadWorkIcon;
|
||||
private OsmandMapTileView view;
|
||||
private Paint paint;
|
||||
private Map<Long, Location> missingRoads;
|
||||
private Map<Long, Location> missingRoadLocations;
|
||||
private List<RouteDataObject> missingRoads;
|
||||
|
||||
public ImpassableRoadsLayer(MapActivity activity) {
|
||||
this.activity = activity;
|
||||
|
@ -44,8 +50,8 @@ public class ImpassableRoadsLayer extends OsmandMapLayer {
|
|||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
for (long id : getMissingRoads().keySet()) {
|
||||
Location location = getMissingRoads().get(id);
|
||||
for (long id : getMissingRoadLocations().keySet()) {
|
||||
Location location = getMissingRoadLocations().get(id);
|
||||
float x = tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
float y = tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
float left = x - roadWorkIcon.getWidth() / 2;
|
||||
|
@ -55,9 +61,16 @@ public class ImpassableRoadsLayer extends OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
|
||||
public Map<Long, Location> getMissingRoads() {
|
||||
public Map<Long, Location> getMissingRoadLocations() {
|
||||
if(missingRoadLocations == null) {
|
||||
missingRoadLocations = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations();
|
||||
}
|
||||
return missingRoadLocations;
|
||||
}
|
||||
|
||||
public List<RouteDataObject> getMissingRoads() {
|
||||
if(missingRoads == null) {
|
||||
missingRoads = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations();
|
||||
missingRoads = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoads();
|
||||
}
|
||||
return missingRoads;
|
||||
}
|
||||
|
@ -71,4 +84,82 @@ public class ImpassableRoadsLayer extends OsmandMapLayer {
|
|||
public boolean drawInScreenPixels() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getRadiusPoi(RotatedTileBox tb){
|
||||
int r = 0;
|
||||
if(tb.getZoom() < startZoom){
|
||||
r = 0;
|
||||
} else {
|
||||
r = 15;
|
||||
}
|
||||
return (int) (r * tb.getDensity());
|
||||
}
|
||||
|
||||
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
|
||||
return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableSingleTap() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableLongPressOnMap() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
|
||||
int ex = (int) point.x;
|
||||
int ey = (int) point.y;
|
||||
int compare = getRadiusPoi(tileBox);
|
||||
int radius = compare * 3 / 2;
|
||||
|
||||
for (RouteDataObject road : getMissingRoads()) {
|
||||
Location location = getMissingRoadLocations().get(road.getId());
|
||||
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
if (calculateBelongs(ex, ey, x, y, compare)) {
|
||||
compare = radius;
|
||||
o.add(road);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LatLon getObjectLocation(Object o) {
|
||||
if (o instanceof OsmPoint) {
|
||||
return new LatLon(((OsmPoint)o).getLatitude(),((OsmPoint)o).getLongitude());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getObjectDescription(Object o) {
|
||||
if(o instanceof OsmPoint) {
|
||||
OsmPoint point = (OsmPoint) o;
|
||||
return OsmEditingPlugin.getEditName(point);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointDescription getObjectName(Object o) {
|
||||
if(o instanceof OsmPoint) {
|
||||
OsmPoint point = (OsmPoint) o;
|
||||
String name = "";
|
||||
String type = "";
|
||||
if (point.getGroup() == OsmPoint.Group.POI){
|
||||
name = ((OpenstreetmapPoint) point).getName();
|
||||
type = PointDescription.POINT_TYPE_OSM_NOTE;
|
||||
} else if (point.getGroup() == OsmPoint.Group.BUG) {
|
||||
name = ((OsmNotesPoint) point).getText();
|
||||
type = PointDescription.POINT_TYPE_OSM_BUG;
|
||||
}
|
||||
return new PointDescription(type, name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue