Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ca7603590a
3 changed files with 92 additions and 28 deletions
|
@ -2,6 +2,7 @@ package net.osmand.data;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.osm.PoiCategory;
|
import net.osmand.osm.PoiCategory;
|
||||||
|
import net.osmand.osm.edit.Node;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -17,6 +18,8 @@ import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
|
|
||||||
|
|
||||||
public class Amenity extends MapObject {
|
public class Amenity extends MapObject {
|
||||||
|
|
||||||
|
@ -33,6 +36,8 @@ public class Amenity extends MapObject {
|
||||||
private String openingHours;
|
private String openingHours;
|
||||||
private Map<String, String> additionalInfo;
|
private Map<String, String> additionalInfo;
|
||||||
private AmenityRoutePoint routePoint; // for search on path
|
private AmenityRoutePoint routePoint; // for search on path
|
||||||
|
private TIntArrayList x;
|
||||||
|
private TIntArrayList y;
|
||||||
|
|
||||||
public Amenity() {
|
public Amenity() {
|
||||||
}
|
}
|
||||||
|
@ -60,6 +65,20 @@ public class Amenity extends MapObject {
|
||||||
this.subType = subType;
|
this.subType = subType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TIntArrayList getX() {
|
||||||
|
if (x == null) {
|
||||||
|
x = new TIntArrayList();
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TIntArrayList getY() {
|
||||||
|
if (y == null) {
|
||||||
|
y = new TIntArrayList();
|
||||||
|
}
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
public String getOpeningHours() {
|
public String getOpeningHours() {
|
||||||
// getAdditionalInfo("opening_hours");
|
// getAdditionalInfo("opening_hours");
|
||||||
return openingHours;
|
return openingHours;
|
||||||
|
|
|
@ -480,6 +480,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearSelectedObject(Object object) {
|
private void clearSelectedObject(Object object) {
|
||||||
|
mapActivity.getMapLayers().getContextMenuLayer().setSelectedObject(null);
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) {
|
for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) {
|
||||||
if (l instanceof ContextMenuLayer.IContextMenuProvider) {
|
if (l instanceof ContextMenuLayer.IContextMenuProvider) {
|
||||||
|
@ -495,6 +496,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSelectedObject(@Nullable Object object) {
|
private void setSelectedObject(@Nullable Object object) {
|
||||||
|
mapActivity.getMapLayers().getContextMenuLayer().setSelectedObject(object);
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) {
|
for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) {
|
||||||
if (l instanceof ContextMenuLayer.IContextMenuProvider) {
|
if (l instanceof ContextMenuLayer.IContextMenuProvider) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.FrameLayout.LayoutParams;
|
import android.widget.FrameLayout.LayoutParams;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.CallbackWithObject;
|
import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.NativeLibrary.RenderedObject;
|
import net.osmand.NativeLibrary.RenderedObject;
|
||||||
import net.osmand.RenderingContext;
|
import net.osmand.RenderingContext;
|
||||||
|
@ -32,8 +33,6 @@ import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.osm.PoiCategory;
|
import net.osmand.osm.PoiCategory;
|
||||||
import net.osmand.osm.PoiFilter;
|
import net.osmand.osm.PoiFilter;
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
import net.osmand.osm.edit.Node;
|
|
||||||
import net.osmand.osm.edit.OsmMapUtils;
|
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuItem;
|
import net.osmand.plus.ContextMenuItem;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -51,6 +50,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
|
|
||||||
public class ContextMenuLayer extends OsmandMapLayer {
|
public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
//private static final Log LOG = PlatformUtil.getLog(ContextMenuLayer.class);
|
//private static final Log LOG = PlatformUtil.getLog(ContextMenuLayer.class);
|
||||||
public static final int VIBRATE_SHORT = 100;
|
public static final int VIBRATE_SHORT = 100;
|
||||||
|
@ -65,6 +66,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
private ImageView contextMarker;
|
private ImageView contextMarker;
|
||||||
private Paint paint;
|
private Paint paint;
|
||||||
|
private Paint outlinePaint;
|
||||||
private Bitmap pressedBitmap;
|
private Bitmap pressedBitmap;
|
||||||
private Bitmap pressedBitmapSmall;
|
private Bitmap pressedBitmapSmall;
|
||||||
private List<LatLon> pressedLatLonFull = new ArrayList<>();
|
private List<LatLon> pressedLatLonFull = new ArrayList<>();
|
||||||
|
@ -81,6 +83,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
private boolean mInGpxDetailsMode;
|
private boolean mInGpxDetailsMode;
|
||||||
|
|
||||||
private List<String> publicTransportTypes;
|
private List<String> publicTransportTypes;
|
||||||
|
private Object selectedObject;
|
||||||
|
|
||||||
public ContextMenuLayer(MapActivity activity) {
|
public ContextMenuLayer(MapActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
@ -110,12 +113,27 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
paint = new Paint();
|
paint = new Paint();
|
||||||
pressedBitmap = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap);
|
pressedBitmap = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap);
|
||||||
pressedBitmapSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap_small);
|
pressedBitmapSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap_small);
|
||||||
|
|
||||||
|
outlinePaint = new Paint();
|
||||||
|
outlinePaint.setStyle(Paint.Style.STROKE);
|
||||||
|
outlinePaint.setAntiAlias(true);
|
||||||
|
outlinePaint.setStrokeWidth(AndroidUtils.dpToPx(activity, 2f));
|
||||||
|
outlinePaint.setStrokeCap(Paint.Cap.ROUND);
|
||||||
|
outlinePaint.setColor(activity.getResources().getColor(R.color.osmand_orange));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
return menu.isActive();
|
return menu.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getSelectedObject() {
|
||||||
|
return selectedObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedObject(Object selectedObject) {
|
||||||
|
this.selectedObject = selectedObject;
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> getPublicTransportTypes() {
|
private List<String> getPublicTransportTypes() {
|
||||||
if (publicTransportTypes == null) {
|
if (publicTransportTypes == null) {
|
||||||
publicTransportTypes = new ArrayList<>();
|
publicTransportTypes = new ArrayList<>();
|
||||||
|
@ -136,6 +154,35 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
|
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
|
||||||
|
if (selectedObject != null) {
|
||||||
|
TIntArrayList x = null;
|
||||||
|
TIntArrayList y = null;
|
||||||
|
if (selectedObject instanceof Amenity) {
|
||||||
|
Amenity a = (Amenity) selectedObject;
|
||||||
|
x = a.getX();
|
||||||
|
y = a.getY();
|
||||||
|
} else if (selectedObject instanceof RenderedObject) {
|
||||||
|
RenderedObject r = (RenderedObject) selectedObject;
|
||||||
|
x = r.getX();
|
||||||
|
y = r.getY();
|
||||||
|
}
|
||||||
|
if (x != null && y != null && x.size() > 2) {
|
||||||
|
double lat = MapUtils.get31LatitudeY(y.get(0));
|
||||||
|
double lon = MapUtils.get31LongitudeX(x.get(0));
|
||||||
|
int px,py, prevX, prevY;
|
||||||
|
prevX = (int) box.getPixXFromLatLon(lat, lon);
|
||||||
|
prevY = (int) box.getPixYFromLatLon(lat, lon);
|
||||||
|
for (int i = 1; i < x.size(); i++) {
|
||||||
|
lat = MapUtils.get31LatitudeY(y.get(i));
|
||||||
|
lon = MapUtils.get31LongitudeX(x.get(i));
|
||||||
|
px = (int) box.getPixXFromLatLon(lat, lon);
|
||||||
|
py = (int) box.getPixYFromLatLon(lat, lon);
|
||||||
|
canvas.drawLine(prevX, prevY, px, py, outlinePaint);
|
||||||
|
prevX = px;
|
||||||
|
prevY = py;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (LatLon latLon : pressedLatLonSmall) {
|
for (LatLon latLon : pressedLatLonSmall) {
|
||||||
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||||
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||||
|
@ -422,7 +469,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
|
private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
|
||||||
LatLon customLatLon = null;
|
LatLon objectLatLon = null;
|
||||||
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false);
|
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false);
|
||||||
NativeOsmandLibrary nativeLib = NativeOsmandLibrary.getLoadedLibrary();
|
NativeOsmandLibrary nativeLib = NativeOsmandLibrary.getLoadedLibrary();
|
||||||
if (nativeLib != null) {
|
if (nativeLib != null) {
|
||||||
|
@ -461,12 +508,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
for (RenderedObject renderedObject : renderedObjects) {
|
for (RenderedObject renderedObject : renderedObjects) {
|
||||||
if (renderedObject.getX() != null && renderedObject.getX().size() == 1
|
if (renderedObject.getX() != null && renderedObject.getX().size() == 1
|
||||||
&& renderedObject.getY() != null && renderedObject.getY().size() == 1) {
|
&& renderedObject.getY() != null && renderedObject.getY().size() == 1) {
|
||||||
customLatLon = new LatLon(MapUtils.get31LatitudeY(renderedObject.getY().get(0)),
|
objectLatLon = new LatLon(MapUtils.get31LatitudeY(renderedObject.getY().get(0)),
|
||||||
MapUtils.get31LongitudeX(renderedObject.getX().get(0)));
|
MapUtils.get31LongitudeX(renderedObject.getX().get(0)));
|
||||||
} else if(renderedObject.getLabelLatLon() != null) {
|
} else if (renderedObject.getLabelLatLon() != null) {
|
||||||
customLatLon = renderedObject.getLabelLatLon();
|
objectLatLon = renderedObject.getLabelLatLon();
|
||||||
} else {
|
|
||||||
customLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
|
|
||||||
}
|
}
|
||||||
if (renderedObject.getId() != null) {
|
if (renderedObject.getId() != null) {
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
|
@ -478,21 +523,19 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
names.add(entry.getValue());
|
names.add(entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Amenity amenity = findAmenity(renderedObject.getId() >> 7, names,
|
LatLon searchLatLon = objectLatLon;
|
||||||
customLatLon.getLatitude(), customLatLon.getLongitude());
|
if (searchLatLon == null) {
|
||||||
if (amenity != null) {
|
searchLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
|
||||||
selectedObjects.put(amenity, poiMenuProvider);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
Amenity amenity = findAmenity(renderedObject.getId() >> 7, names, searchLatLon);
|
||||||
|
if (amenity != null) {
|
||||||
if (renderedObject.getX() != null && renderedObject.getX().size() > 1
|
if (renderedObject.getX() != null && renderedObject.getX().size() > 1
|
||||||
&& renderedObject.getY() != null && renderedObject.getY().size() > 1) {
|
&& renderedObject.getY() != null && renderedObject.getY().size() > 1) {
|
||||||
|
amenity.getX().addAll(renderedObject.getX());
|
||||||
List<Node> nodes = new ArrayList<>(renderedObject.getX().size());
|
amenity.getY().addAll(renderedObject.getY());
|
||||||
for (int i = 0; i < renderedObject.getX().size(); i++) {
|
|
||||||
nodes.add(new Node(MapUtils.get31LatitudeY(renderedObject.getY().get(i)),
|
|
||||||
MapUtils.get31LongitudeX(renderedObject.getX().get(i)), 0));
|
|
||||||
}
|
}
|
||||||
//customLatLon = OsmMapUtils.getMathWeightCenterForNodes(nodes);
|
selectedObjects.put(amenity, poiMenuProvider);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
selectedObjects.put(renderedObject, null);
|
selectedObjects.put(renderedObject, null);
|
||||||
}
|
}
|
||||||
|
@ -509,7 +552,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
pointDescription = provider.getObjectName(selectedObj);
|
pointDescription = provider.getObjectName(selectedObj);
|
||||||
}
|
}
|
||||||
if (latLon == null) {
|
if (latLon == null) {
|
||||||
latLon = customLatLon;
|
latLon = objectLatLon;
|
||||||
}
|
}
|
||||||
if (latLon == null) {
|
if (latLon == null) {
|
||||||
latLon = getLatLon(point, tileBox);
|
latLon = getLatLon(point, tileBox);
|
||||||
|
@ -661,8 +704,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Amenity findAmenity(long id, List<String> names, double lat, double lon) {
|
private Amenity findAmenity(long id, List<String> names, LatLon latLon) {
|
||||||
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 50);
|
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 50);
|
||||||
List<Amenity> amenities = activity.getMyApplication().getResourceManager().searchAmenities(
|
List<Amenity> amenities = activity.getMyApplication().getResourceManager().searchAmenities(
|
||||||
new BinaryMapIndexReader.SearchPoiTypeFilter() {
|
new BinaryMapIndexReader.SearchPoiTypeFilter() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue