Marker repositioning implemented.
This commit is contained in:
parent
cdb1fd41c5
commit
c5fc752bdd
3 changed files with 120 additions and 24 deletions
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.LocationPoint;
|
||||
|
@ -80,6 +81,37 @@ public class MapMarkersHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
MapMarker mapMarker = (MapMarker) o;
|
||||
|
||||
if (colorIndex != mapMarker.colorIndex) return false;
|
||||
if (pos != mapMarker.pos) return false;
|
||||
if (index != mapMarker.index) return false;
|
||||
if (history != mapMarker.history) return false;
|
||||
if (selected != mapMarker.selected) return false;
|
||||
if (dist != mapMarker.dist) return false;
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (!point.equals(mapMarker.point)) return false;
|
||||
return pointDescription != null ? pointDescription.equals(mapMarker.pointDescription) : mapMarker.pointDescription == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = point.hashCode();
|
||||
result = 31 * result + (pointDescription != null ? pointDescription.hashCode() : 0);
|
||||
result = 31 * result + colorIndex;
|
||||
result = 31 * result + pos;
|
||||
result = 31 * result + index;
|
||||
result = 31 * result + (history ? 1 : 0);
|
||||
result = 31 * result + (selected ? 1 : 0);
|
||||
result = 31 * result + dist;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public MapMarkersHelper(OsmandApplication ctx) {
|
||||
|
@ -363,6 +395,14 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) {
|
||||
if (marker != null) {
|
||||
settings.moveMapMarker(new LatLon(marker.getLatitude(), marker.getLongitude()), latLon);
|
||||
readFromSettings();
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMapMarker(MapMarker marker) {
|
||||
if (marker != null) {
|
||||
settings.deleteMapMarker(marker.index);
|
||||
|
|
|
@ -40,7 +40,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
|
@ -50,7 +49,6 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class OsmandSettings {
|
||||
|
||||
|
@ -1875,6 +1873,20 @@ public class OsmandSettings {
|
|||
return savePoints(ps, ds, cs, ns, bs);
|
||||
}
|
||||
|
||||
public boolean movePoint(LatLon latLonEx, LatLon latLonNew) {
|
||||
List<LatLon> ps = getPoints();
|
||||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Integer> ns = getPositions(ps.size());
|
||||
List<Boolean> bs = getSelections(ps.size());
|
||||
int index = ps.indexOf(latLonEx);
|
||||
|
||||
if (ps.size() > index) {
|
||||
ps.set(index, latLonNew);
|
||||
}
|
||||
return savePoints(ps, ds, cs, ns, bs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePoint(int index) {
|
||||
List<LatLon> ps = getPoints();
|
||||
|
@ -2137,6 +2149,10 @@ public class OsmandSettings {
|
|||
pos, selected);
|
||||
}
|
||||
|
||||
public boolean moveMapMarker(LatLon latLonEx, LatLon latLonNew) {
|
||||
return mapMarkersStorage.movePoint(latLonEx, latLonNew);
|
||||
}
|
||||
|
||||
public boolean deleteMapMarker(int index) {
|
||||
return mapMarkersStorage.deletePoint(index);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,11 @@ import android.graphics.PorterDuff;
|
|||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
|
@ -31,7 +34,8 @@ import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection {
|
||||
public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider,
|
||||
IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider {
|
||||
protected static final int DIST_TO_SHOW = 80;
|
||||
protected static final long USE_FINGER_LOCATION_DELAY = 1000;
|
||||
private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 6;
|
||||
|
@ -71,6 +75,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
private GestureDetector longTapDetector;
|
||||
private Handler handler;
|
||||
|
||||
private ContextMenuLayer contextMenuLayer;
|
||||
|
||||
public MapMarkersLayer(MapActivity map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
@ -108,10 +114,12 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
paint.setAntiAlias(true);
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
paint.setStrokeJoin(Paint.Join.ROUND);
|
||||
paint.setColor(map.getResources().getColor(R.color.marker_red));
|
||||
paint.setColor(ContextCompat.getColor(map, R.color.marker_red));
|
||||
paint.setAlpha(200);
|
||||
|
||||
widgetsFactory = new MapMarkersWidgetsFactory(map);
|
||||
|
||||
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
||||
}
|
||||
|
||||
private Paint createPaintDest(int colorId) {
|
||||
|
@ -119,7 +127,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
paint.setDither(true);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setFilterBitmap(true);
|
||||
int color = map.getResources().getColor(colorId);
|
||||
int color = ContextCompat.getColor(map, colorId);
|
||||
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
|
||||
return paint;
|
||||
}
|
||||
|
@ -216,11 +224,11 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
|
||||
|
||||
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tb.getZoom());
|
||||
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom());
|
||||
|
||||
if (tb.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
|
||||
if (tileBox.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -230,14 +238,14 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
boolean first = true;
|
||||
Location myLocation = map.getMapViewTrackingUtilities().getMyLocation();
|
||||
if (markersHelper.isStartFromMyLocation() && myLocation != null) {
|
||||
int locationX = tb.getPixXFromLonNoRot(myLocation.getLongitude());
|
||||
int locationY = tb.getPixYFromLatNoRot(myLocation.getLatitude());
|
||||
int locationX = tileBox.getPixXFromLonNoRot(myLocation.getLongitude());
|
||||
int locationY = tileBox.getPixYFromLatNoRot(myLocation.getLatitude());
|
||||
path.moveTo(locationX, locationY);
|
||||
first = false;
|
||||
}
|
||||
for (LatLon point : route) {
|
||||
int locationX = tb.getPixXFromLonNoRot(point.getLongitude());
|
||||
int locationY = tb.getPixYFromLatNoRot(point.getLatitude());
|
||||
int locationX = tileBox.getPixXFromLonNoRot(point.getLongitude());
|
||||
int locationY = tileBox.getPixYFromLatNoRot(point.getLatitude());
|
||||
if (first) {
|
||||
path.moveTo(locationX, locationY);
|
||||
first = false;
|
||||
|
@ -249,17 +257,17 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
}
|
||||
|
||||
List<MapMarker> activeMapMarkers = markersHelper.getActiveMapMarkers();
|
||||
for (int i = 0; i < activeMapMarkers.size(); i++) {
|
||||
MapMarker marker = activeMapMarkers.get(i);
|
||||
if (isLocationVisible(tb, marker) && !overlappedByWaypoint(marker)) {
|
||||
for (MapMarker marker : activeMapMarkers) {
|
||||
if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker)
|
||||
&& !isInMotion(marker)) {
|
||||
Bitmap bmp = getMapMarkerBitmap(marker.colorIndex);
|
||||
int marginX = bmp.getWidth() / 6;
|
||||
int marginY = bmp.getHeight();
|
||||
int locationX = tb.getPixXFromLonNoRot(marker.getLongitude());
|
||||
int locationY = tb.getPixYFromLatNoRot(marker.getLatitude());
|
||||
canvas.rotate(-tb.getRotate(), locationX, locationY);
|
||||
int locationX = tileBox.getPixXFromLonNoRot(marker.getLongitude());
|
||||
int locationY = tileBox.getPixYFromLatNoRot(marker.getLatitude());
|
||||
canvas.rotate(-tileBox.getRotate(), locationX, locationY);
|
||||
canvas.drawBitmap(bmp, locationX - marginX, locationY - marginY, bitmapPaint);
|
||||
canvas.rotate(tb.getRotate(), locationX, locationY);
|
||||
canvas.rotate(tileBox.getRotate(), locationX, locationY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,21 +277,21 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
if (show) {
|
||||
LatLon loc = fingerLocation;
|
||||
if (!useFingerLocation) {
|
||||
loc = tb.getCenterLatLon();
|
||||
loc = tileBox.getCenterLatLon();
|
||||
}
|
||||
if (loc != null) {
|
||||
List<MapMarker> sortedMapMarkers = markersHelper.getSortedMapMarkers();
|
||||
int i = 0;
|
||||
for (MapMarker marker : sortedMapMarkers) {
|
||||
if (!isLocationVisible(tb, marker)) {
|
||||
if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) {
|
||||
canvas.save();
|
||||
net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(),
|
||||
marker.getLatitude(), marker.getLongitude(), calculations);
|
||||
float bearing = calculations[1] - 90;
|
||||
float radiusBearing = DIST_TO_SHOW * tb.getDensity();
|
||||
final QuadPoint cp = tb.getCenterPixelPoint();
|
||||
float radiusBearing = DIST_TO_SHOW * tileBox.getDensity();
|
||||
final QuadPoint cp = tileBox.getCenterPixelPoint();
|
||||
canvas.rotate(bearing, cp.x, cp.y);
|
||||
canvas.translate(-24 * tb.getDensity() + radiusBearing, -22 * tb.getDensity());
|
||||
canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity());
|
||||
canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex));
|
||||
canvas.restore();
|
||||
}
|
||||
|
@ -294,9 +302,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (contextMenuLayer.getMoveableObject() instanceof MapMarker) {
|
||||
MapMarker objectInMotion = (MapMarker) contextMenuLayer.getMoveableObject();
|
||||
Bitmap bitmap = getMapMarkerBitmap(objectInMotion.colorIndex);
|
||||
PointF pf = contextMenuLayer.getMoveableCenterPoint(tileBox);
|
||||
int marginX = bitmap.getWidth() / 6;
|
||||
int marginY = bitmap.getHeight();
|
||||
float locationX = pf.x;
|
||||
float locationY = pf.y;
|
||||
canvas.rotate(-tileBox.getRotate(), locationX, locationY);
|
||||
canvas.drawBitmap(bitmap, locationX - marginX, locationY - marginY, bitmapPaint);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInMotion(@NonNull MapMarker marker) {
|
||||
return marker.equals(contextMenuLayer.getMoveableObject());
|
||||
}
|
||||
|
||||
public boolean isLocationVisible(RotatedTileBox tb, MapMarker marker) {
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (marker == null || tb == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -482,4 +507,19 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
public void clearSelectedObject() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isObjectMoveable(Object o) {
|
||||
return o instanceof MapMarker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyNewObjectPosition(Object o, LatLon position) {
|
||||
if (o instanceof MapMarker) {
|
||||
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
|
||||
MapMarker marker = (MapMarker) o;
|
||||
markersHelper.moveMapMarker(marker, position);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue