From 38a41d1b025e6838c06f21fcce908c54d6e78b5a Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 3 Apr 2017 21:46:20 +0200 Subject: [PATCH] Fix https://github.com/osmandapp/Osmand/issues/3248 --- .../plus/render/MapRenderRepositories.java | 2 +- .../osmand/plus/views/ContextMenuLayer.java | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 5f93fc28e9..5c04d13d75 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -792,7 +792,6 @@ public class MapRenderRepositories { } String renderingDebugInfo = currentRenderingContext.renderingDebugInfo; currentRenderingContext.ended = true; - visibleRenderingContext = currentRenderingContext; if (checkWhetherInterrupted()) { // revert if it was interrupted // (be smart a bit do not revert if road already drawn) @@ -806,6 +805,7 @@ public class MapRenderRepositories { currentRenderingContext = null; return; } else { + visibleRenderingContext = currentRenderingContext; this.checkedRenderedState = renderedState; this.checkedBox = this.bmpLocation; } diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 236c0a1a79..f01120fc96 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -437,9 +437,31 @@ public class ContextMenuLayer extends OsmandMapLayer { renderedObjects = nativeLib.searchRenderedObjectsFromContext(rc, (int) (point.x - x), (int) (point.y - y)); } if (renderedObjects != null) { + // double tx = c.first/ (rc->tileDivisor); + // double ty = c.second / (rc->tileDivisor); + // float dTileX = tx - rc->getLeft(); + // float dTileY = ty - rc->getTop(); + // rc->calcX = rc->cosRotateTileSize * dTileX - rc->sinRotateTileSize * dTileY; + // rc->calcY = rc->sinRotateTileSize * dTileX + rc->cosRotateTileSize * dTileY; + int TILE_SIZE = 256; + double cosRotateTileSize = Math.cos(Math.toRadians(rc.rotate)) * TILE_SIZE; + double sinRotateTileSize = Math.sin(Math.toRadians(rc.rotate)) * TILE_SIZE; + for(RenderedObject r : renderedObjects) { + double cx = r.getBbox().centerX(); + double cy = r.getBbox().centerY(); + double dTileX = (cx * cosRotateTileSize + cy * sinRotateTileSize) / (TILE_SIZE * TILE_SIZE); + double dTileY = (cy * cosRotateTileSize - cx * sinRotateTileSize) / (TILE_SIZE * TILE_SIZE); + int x31 = (int) ((dTileX + rc.leftX) * rc.tileDivisor); + int y31 = (int) ((dTileY + rc.topY) * rc.tileDivisor); + double lat = MapUtils.get31LatitudeY(y31); + double lon = MapUtils.get31LongitudeX(x31); + r.setLabelLatLon(new LatLon(lat, lon)); + } IContextMenuProvider poiMenuProvider = activity.getMapLayers().getPoiMapLayer(); for (RenderedObject renderedObject : renderedObjects) { - if (renderedObject.getX() != null && renderedObject.getX().size() == 1 + if(renderedObject.getLabelLatLon() != null) { + customLatLon = renderedObject.getLabelLatLon(); + } else if (renderedObject.getX() != null && renderedObject.getX().size() == 1 && renderedObject.getY() != null && renderedObject.getY().size() == 1) { customLatLon = new LatLon(MapUtils.get31LatitudeY(renderedObject.getY().get(0)), MapUtils.get31LongitudeX(renderedObject.getX().get(0))); @@ -452,7 +474,7 @@ public class ContextMenuLayer extends OsmandMapLayer { names.add(renderedObject.getName()); } for (Entry entry : renderedObject.getTags().entrySet()) { - if (entry.getKey().startsWith("name")) { + if (entry.getKey().startsWith("name:") && !entry.getValue().equals("")) { names.add(entry.getValue()); } } @@ -470,7 +492,7 @@ public class ContextMenuLayer extends OsmandMapLayer { nodes.add(new Node(MapUtils.get31LatitudeY(renderedObject.getY().get(i)), MapUtils.get31LongitudeX(renderedObject.getX().get(i)), 0)); } - customLatLon = OsmMapUtils.getMathWeightCenterForNodes(nodes); + //customLatLon = OsmMapUtils.getMathWeightCenterForNodes(nodes); } selectedObjects.put(renderedObject, null); }