From 8751e5dcadeecb3de4e9323c0f9a199287f0f9a6 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 17 May 2017 22:43:26 +0300 Subject: [PATCH] Fix mapillary vector lines. Added mapillary image context menu. --- .../plus/mapcontextmenu/MapContextMenu.java | 26 ++++--- .../plus/mapcontextmenu/MenuController.java | 8 ++- .../plus/mapillary/MapillaryImageDialog.java | 11 +++ .../mapillary/MapillaryMenuController.java | 67 +++++++++++++++++++ .../plus/mapillary/MapillaryVectorLayer.java | 37 ++++++---- 5 files changed, 125 insertions(+), 24 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapillary/MapillaryMenuController.java diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index a755fcce58..db9c5d808b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -305,7 +305,11 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL appModeChanged = false; if (needAcquireMenuController) { - acquireMenuController(restorePrevious); + if (!acquireMenuController(restorePrevious)) { + active = false; + clearSelectedObject(object); + return false; + } } else { menuController.update(pointDescription, object); } @@ -510,7 +514,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } - private void acquireMenuController(boolean restorePrevious) { + private boolean acquireMenuController(boolean restorePrevious) { MapContextMenuData menuData = null; if (menuController != null) { if (menuController.isActive() && !restorePrevious) { @@ -521,13 +525,17 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL menuController.onAcquireNewController(pointDescription, object); } menuController = MenuController.getMenuController(mapActivity, latLon, pointDescription, object, MenuType.STANDARD); - menuController.setActive(true); - if (menuData != null && (object != menuData.getObject()) - && (menuController.hasBackAction() || menuData.hasBackAction())) { - historyStack.add(menuData); - } - if (!(menuController instanceof MapDataMenuController)) { - menuController.buildMapDownloadButton(latLon); + if (menuController.setActive(true)) { + if (menuData != null && (object != menuData.getObject()) + && (menuController.hasBackAction() || menuData.hasBackAction())) { + historyStack.add(menuData); + } + if (!(menuController instanceof MapDataMenuController)) { + menuController.buildMapDownloadButton(latLon); + } + return true; + } else { + return false; } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index fa32978da4..a95c7d788e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -52,6 +52,8 @@ import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute; import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController; import net.osmand.plus.mapcontextmenu.other.ShareMenu; +import net.osmand.plus.mapillary.MapillaryImage; +import net.osmand.plus.mapillary.MapillaryMenuController; import net.osmand.plus.osmedit.EditPOIMenuController; import net.osmand.plus.osmedit.OsmBugMenuController; import net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote; @@ -127,7 +129,6 @@ public abstract class MenuController extends BaseMenuController { public static MenuController getMenuController(MapActivity mapActivity, LatLon latLon, PointDescription pointDescription, Object object, MenuType menuType) { - OsmandApplication app = mapActivity.getMyApplication(); MenuController menuController = null; if (object != null) { if (object instanceof Amenity) { @@ -170,6 +171,8 @@ public abstract class MenuController extends BaseMenuController { menuController = new ImpassibleRoadsMenuController(mapActivity, pointDescription, (RouteDataObject) object); } else if (object instanceof RenderedObject) { menuController = new RenderedObjectMenuController(mapActivity, pointDescription, (RenderedObject) object); + } else if (object instanceof MapillaryImage) { + menuController = new MapillaryMenuController(mapActivity, pointDescription, (MapillaryImage) object); } } if (menuController == null) { @@ -197,8 +200,9 @@ public abstract class MenuController extends BaseMenuController { return active; } - public void setActive(boolean active) { + public boolean setActive(boolean active) { this.active = active; + return true; } public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl, OnClickListener onClickListener) { diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java index 414873655f..8024080f29 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java @@ -252,6 +252,17 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { return dialog; } + public static MapillaryImageDialog show(MapActivity mapActivity, double latitude, double longitude, + String key, double ca, String title, String description) { + String imageUrl = MAPILLARY_HIRES_IMAGE_URL_TEMPLATE + key; + String viewerUrl = MAPILLARY_VIEWER_URL_TEMPLATE + key; + LatLon latLon = new LatLon(latitude, longitude); + MapillaryImageDialog dialog = new MapillaryImageDialog(mapActivity, key, imageUrl, viewerUrl, + latLon, ca, title, description); + ContextMenuCardDialogFragment.showInstance(dialog); + return dialog; + } + private class DownloadImageTask extends AsyncTask { private ProgressBar progressBar; diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryMenuController.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryMenuController.java new file mode 100644 index 0000000000..8c1d224846 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryMenuController.java @@ -0,0 +1,67 @@ +package net.osmand.plus.mapillary; + +import android.graphics.drawable.Drawable; + +import net.osmand.data.PointDescription; +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.util.Algorithms; + +public class MapillaryMenuController extends MenuController { + + private MapillaryImage image; + + public MapillaryMenuController(MapActivity mapActivity, PointDescription pointDescription, MapillaryImage image) { + super(new MenuBuilder(mapActivity), pointDescription, mapActivity); + this.image = image; + } + + @Override + protected void setObject(Object object) { + if (object instanceof MapillaryImage) { + this.image = (MapillaryImage) object; + } + } + + @Override + public boolean setActive(boolean active) { + if (image != null && getMenuType() == MenuType.STANDARD) { + MapillaryImageDialog.show(getMapActivity(), image.getLatitude(), image.getLongitude(), + image.getKey(), image.getCa(), getMapActivity().getMyApplication().getString(R.string.mapillary), null); + return false; + } else { + return super.setActive(active); + } + } + + @Override + protected Object getObject() { + return image; + } + + public MapillaryImage getMapillaryImage() { + return image; + } + + @Override + public boolean needTypeStr() { + return !Algorithms.isEmpty(getNameStr()); + } + + @Override + public boolean displayDistanceDirection() { + return true; + } + + @Override + public Drawable getLeftIcon() { + return getIcon(R.drawable.ic_action_mapillary, R.color.mapillary_color); + } + + @Override + public boolean needStreetName() { + return true; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryVectorLayer.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryVectorLayer.java index 304fdd1788..6fcae266c2 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryVectorLayer.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryVectorLayer.java @@ -8,9 +8,9 @@ import android.graphics.PointF; import android.support.v4.content.ContextCompat; import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.CoordinateSequence; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.Point; import net.osmand.AndroidUtils; @@ -194,14 +194,14 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont QuadRect tileBounds = tileBox.getTileBounds(); double px, py, tx, ty; float x, y; - float lx = -1000f; - float ly = -1000f; float pw = point.getWidth(); float ph = point.getHeight(); float pwd = pw / 2; float phd = ph / 2; - float pwm = pw * 2; - float phm = ph * 2; + //float lx = -1000f; + //float ly = -1000f; + //float pwm = pw * 2; + //float phm = ph * 2; canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); for (List points : seqMap.values()) { for (int i = 0; i < points.size(); i++) { @@ -218,8 +218,8 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont //if (!QuadRect.intersects(rLast, rNow) || i == points.size() - 1) { canvas.drawBitmap(point, x - pwd, y - phd, paintPoint); visiblePoints.put(new QuadPointDouble(tileX + px, tileY + py), (Map) p.getUserData()); - lx = x; - ly = y; + //lx = x; + //ly = y; //} } } @@ -232,20 +232,31 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont if (g instanceof LineString && !g.isEmpty()) { LineString l = (LineString) g; if (l.getCoordinateSequence() != null && !l.isEmpty()) { - draw(l.getCoordinateSequence(), canvas, tileBox, tileX, tileY); + draw(l.getCoordinateSequence().toCoordinateArray(), canvas, tileBox, tileX, tileY); + } + } else if (g instanceof MultiLineString && !g.isEmpty()) { + MultiLineString ml = (MultiLineString) g; + for (int i = 0; i < ml.getNumGeometries(); i++) { + Geometry gm = ml.getGeometryN(i); + if (gm instanceof LineString && !gm.isEmpty()) { + LineString l = (LineString) gm; + if (l.getCoordinateSequence() != null && !l.isEmpty()) { + draw(l.getCoordinateSequence().toCoordinateArray(), canvas, tileBox, tileX, tileY); + } + } } } } } - protected void draw(CoordinateSequence points, Canvas canvas, RotatedTileBox tileBox, int tileX, int tileY) { - if (points.size() > 1) { + protected void draw(Coordinate[] points, Canvas canvas, RotatedTileBox tileBox, int tileX, int tileY) { + if (points.length > 1) { int dzoom = tileBox.getZoom() - TILE_ZOOM; int mult = (int) Math.pow(2.0, dzoom); QuadRect tileBounds = tileBox.getTileBounds(); canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); - Coordinate lastPt = points.getCoordinate(0); + Coordinate lastPt = points[0]; float x; float y; float lastx = 0; @@ -255,9 +266,9 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont double ly = lastPt.y / EXTENT; boolean reCalculateLastXY = true; - int size = points.size(); + int size = points.length; for (int i = 1; i < size; i++) { - Coordinate pt = points.getCoordinate(i); + Coordinate pt = points[i]; px = pt.x / EXTENT; py = pt.y / EXTENT; tpx = (tileX + px) * mult;