Search in sources :

Example 6 with OsmandMapLayer

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

the class MapTextLayer method initLayer.

@Override
public void initLayer(@NonNull OsmandMapTileView v) {
    this.view = v;
    paintTextIcon = new Paint();
    updateTextSize();
    paintTextIcon.setTextAlign(Align.CENTER);
    paintTextIcon.setAntiAlias(true);
    Map<OsmandMapLayer, Collection<?>> textObjectsLoc = new TreeMap<>((lhs, rhs) -> {
        if (view != null) {
            float z1 = view.getZorder(lhs);
            float z2 = view.getZorder(rhs);
            return Float.compare(z1, z2);
        }
        return 0;
    });
    textObjectsLoc.putAll(this.textObjects);
    this.textObjects = textObjectsLoc;
}
Also used : OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) Collection(java.util.Collection) Paint(android.graphics.Paint) TreeMap(java.util.TreeMap)

Example 7 with OsmandMapLayer

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

the class MapTextLayer method onPrepareBufferImage.

@SuppressWarnings("unchecked")
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    QuadTree<QuadRect> intersections = initBoundIntersections(tileBox);
    for (Map.Entry<OsmandMapLayer, Collection<?>> entry : textObjects.entrySet()) {
        OsmandMapLayer l = entry.getKey();
        MapTextProvider provider = (MapTextProvider) l;
        if (!view.isLayerExists(l) || !provider.isTextVisible()) {
            continue;
        }
        updateTextSize();
        paintTextIcon.setFakeBoldText(provider.isFakeBoldText());
        float textSize = paintTextIcon.getTextSize();
        for (Object o : entry.getValue()) {
            LatLon loc = provider.getTextLocation(o);
            String name = provider.getText(o);
            if (loc == null || TextUtils.isEmpty(name)) {
                continue;
            }
            int r = provider.getTextShift(o, tileBox);
            float x = tileBox.getPixXFromLatLon(loc.getLatitude(), loc.getLongitude());
            float y = tileBox.getPixYFromLatLon(loc.getLatitude(), loc.getLongitude());
            drawWrappedText(canvas, name, intersections, x, y + r + 2 + textSize / 2, settings.isNightMode());
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) Collection(java.util.Collection) QuadRect(net.osmand.data.QuadRect) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Paint(android.graphics.Paint)

Example 8 with OsmandMapLayer

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

the class OsmandAidlApi method registerRemoveMapLayerReceiver.

private void registerRemoveMapLayerReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver removeMapLayerReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            MapActivity mapActivity = mapActivityRef.get();
            String layerId = intent.getStringExtra(AIDL_OBJECT_ID);
            String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
            if (mapActivity != null && layerId != null && packName != null) {
                ConnectedApp connectedApp = connectedApps.get(packName);
                if (connectedApp != null) {
                    OsmandMapLayer mapLayer = connectedApp.getMapLayers().remove(layerId);
                    if (mapLayer != null) {
                        mapActivity.getMapView().removeLayer(mapLayer);
                        mapActivity.refreshMap();
                    }
                }
            }
        }
    };
    registerReceiver(removeMapLayerReceiver, mapActivity, AIDL_REMOVE_MAP_LAYER);
}
Also used : Context(android.content.Context) WeakReference(java.lang.ref.WeakReference) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) MapActivity(net.osmand.plus.activities.MapActivity)

Example 9 with OsmandMapLayer

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

the class MapContextMenu method getActionsContextMenuAdapter.

public ContextMenuAdapter getActionsContextMenuAdapter(boolean configure) {
    MapActivity mapActivity = getMapActivity();
    final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(getMyApplication());
    if (mapActivity != null) {
        LatLon latLon = getLatLon();
        for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {
            layer.populateObjectContextMenu(latLon, getObject(), menuAdapter);
        }
        mapActivity.getMapActions().addActionsToAdapter(configure ? 0 : latLon.getLatitude(), configure ? 0 : latLon.getLongitude(), menuAdapter, configure ? null : getObject(), configure);
    }
    return menuAdapter;
}
Also used : LatLon(net.osmand.data.LatLon) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) MapActivity(net.osmand.plus.activities.MapActivity)

Example 10 with OsmandMapLayer

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

the class ContextMenuLayer method disableLongPressOnMap.

public boolean disableLongPressOnMap(PointF point, RotatedTileBox tileBox) {
    MapActivity mapActivity = getMapActivity();
    if (mInChangeMarkerPositionMode || mInGpxDetailsMode || mInAddGpxPointMode || mapActivity == null || mapActivity.getMapRouteInfoMenu().isVisible() || MapRouteInfoMenu.waypointsVisible || MapRouteInfoMenu.followTrackVisible || mapActivity.getGpsFilterFragment() != null || mapActivity.getDownloadTilesFragment() != null) {
        return true;
    }
    boolean res = false;
    for (OsmandMapLayer lt : view.getLayers()) {
        if (lt instanceof IContextMenuProvider) {
            if (((IContextMenuProvider) lt).disableLongPressOnMap(point, tileBox)) {
                res = true;
                break;
            }
        }
    }
    return res;
}
Also used : OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) MapActivity(net.osmand.plus.activities.MapActivity)

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