Search in sources :

Example 11 with OsmandMapLayer

use of net.osmand.plus.views.layers.base.OsmandMapLayer in project Osmand by osmandapp.

the class ContextMenuLayer method selectObjectsForContextMenu.

@NonNull
private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point, boolean acquireObjLatLon, boolean unknownLocation) {
    Map<LatLon, BackgroundType> pressedLatLonFull = new HashMap<>();
    Map<LatLon, BackgroundType> pressedLatLonSmall = new HashMap<>();
    Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
    List<Object> s = new ArrayList<>();
    for (OsmandMapLayer lt : view.getLayers()) {
        if (lt instanceof IContextMenuProvider) {
            s.clear();
            final IContextMenuProvider l = (IContextMenuProvider) lt;
            l.collectObjectsFromPoint(point, tileBox, s, unknownLocation);
            for (Object o : s) {
                selectedObjects.put(o, l);
                if (acquireObjLatLon && l.isObjectClickable(o)) {
                    LatLon latLon = l.getObjectLocation(o);
                    BackgroundType backgroundType = DEFAULT_BACKGROUND_TYPE;
                    if (o instanceof OsmBugsLayer.OpenStreetNote) {
                        backgroundType = BackgroundType.COMMENT;
                    }
                    if (o instanceof FavouritePoint) {
                        backgroundType = ((FavouritePoint) o).getBackgroundType();
                    }
                    if (o instanceof GPXUtilities.WptPt) {
                        backgroundType = BackgroundType.getByTypeName(((GPXUtilities.WptPt) o).getBackgroundType(), DEFAULT_BACKGROUND_TYPE);
                    }
                    if (lt.isPresentInFullObjects(latLon) && !pressedLatLonFull.containsKey(latLon)) {
                        pressedLatLonFull.put(latLon, backgroundType);
                    } else if (lt.isPresentInSmallObjects(latLon) && !pressedLatLonSmall.containsKey(latLon)) {
                        pressedLatLonSmall.put(latLon, backgroundType);
                    }
                }
            }
        }
    }
    if (acquireObjLatLon) {
        this.pressedLatLonFull = pressedLatLonFull;
        this.pressedLatLonSmall = pressedLatLonSmall;
    }
    return selectedObjects;
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) FavouritePoint(net.osmand.data.FavouritePoint) HashMap(java.util.HashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) LatLon(net.osmand.data.LatLon) BackgroundType(net.osmand.data.FavouritePoint.BackgroundType) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) ObfMapObject(net.osmand.core.jni.ObfMapObject) CallbackWithObject(net.osmand.CallbackWithObject) RenderedObject(net.osmand.NativeLibrary.RenderedObject) MapObject(net.osmand.core.jni.MapObject) NonNull(androidx.annotation.NonNull)

Example 12 with OsmandMapLayer

use of net.osmand.plus.views.layers.base.OsmandMapLayer in project Osmand by osmandapp.

the class MapRouteInfoMenu method getObjectLocation.

private Pair<LatLon, PointDescription> getObjectLocation(OsmandMapTileView mapView, PointF point, RotatedTileBox tileBox) {
    List<Object> objects = new ArrayList<>();
    for (OsmandMapLayer layer : mapView.getLayers()) {
        if (layer instanceof IContextMenuProvider) {
            objects.clear();
            IContextMenuProvider provider = (IContextMenuProvider) layer;
            provider.collectObjectsFromPoint(point, tileBox, objects, true);
            for (Object o : objects) {
                if (provider.isObjectClickable(o)) {
                    LatLon latLon = provider.getObjectLocation(o);
                    PointDescription name = null;
                    if (o instanceof FavouritePoint) {
                        name = ((FavouritePoint) o).getPointDescription(mapView.getApplication());
                    }
                    return new Pair<>(latLon, name);
                }
            }
        }
    }
    return null;
}
Also used : LatLon(net.osmand.data.LatLon) FavouritePoint(net.osmand.data.FavouritePoint) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) PointDescription(net.osmand.data.PointDescription) ArrayList(java.util.ArrayList) IContextMenuProvider(net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider) Pair(android.util.Pair)

Example 13 with OsmandMapLayer

use of net.osmand.plus.views.layers.base.OsmandMapLayer in project Osmand by osmandapp.

the class OsmandMapTileView method refreshBaseMapInternal.

private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
    if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
        return;
    }
    if (bufferBitmapTmp == null || tileBox.getPixHeight() != bufferBitmapTmp.getHeight() || tileBox.getPixWidth() != bufferBitmapTmp.getWidth()) {
        bufferBitmapTmp = Bitmap.createBitmap(tileBox.getPixWidth(), tileBox.getPixHeight(), Config.ARGB_8888);
    }
    long start = SystemClock.elapsedRealtime();
    final QuadPoint c = tileBox.getCenterPixelPoint();
    Canvas canvas = new Canvas(bufferBitmapTmp);
    fillCanvas(canvas, drawSettings);
    for (int i = 0; i < layers.size(); i++) {
        try {
            OsmandMapLayer layer = layers.get(i);
            canvas.save();
            // rotate if needed
            if (!layer.drawInScreenPixels()) {
                canvas.rotate(tileBox.getRotate(), c.x, c.y);
            }
            layer.onPrepareBufferImage(canvas, tileBox, drawSettings);
            canvas.restore();
        } catch (IndexOutOfBoundsException e) {
            // skip it
            canvas.restore();
        }
    }
    Bitmap t = bufferBitmap;
    synchronized (this) {
        bufferImgLoc = tileBox;
        bufferBitmap = bufferBitmapTmp;
        bufferBitmapTmp = t;
    }
    long end = SystemClock.elapsedRealtime();
    additional.calculateFPS(start, end);
}
Also used : Bitmap(android.graphics.Bitmap) QuadPoint(net.osmand.data.QuadPoint) Canvas(android.graphics.Canvas) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Aggregations

OsmandMapLayer (net.osmand.plus.views.layers.base.OsmandMapLayer)13 MapActivity (net.osmand.plus.activities.MapActivity)6 Paint (android.graphics.Paint)4 LatLon (net.osmand.data.LatLon)4 SuppressLint (android.annotation.SuppressLint)2 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 WeakReference (java.lang.ref.WeakReference)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 TreeMap (java.util.TreeMap)2 FavouritePoint (net.osmand.data.FavouritePoint)2 QuadPoint (net.osmand.data.QuadPoint)2 AidlMapLayer (net.osmand.plus.views.layers.AidlMapLayer)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Pair (android.util.Pair)1 NonNull (androidx.annotation.NonNull)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1