Search in sources :

Example 1 with PointImageDrawable

use of net.osmand.plus.views.PointImageDrawable in project Osmand by osmandapp.

the class OsmBugsLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    OsmandApplication app = getApplication();
    startZoom = plugin.SHOW_OSM_BUGS_MIN_ZOOM.get();
    if (tileBox.getZoom() >= startZoom) {
        // request to load
        data.queryNewData(tileBox);
        List<OpenStreetNote> objects = data.getResults();
        if (objects != null) {
            float textScale = getTextScale();
            float iconSize = getIconSize(app);
            QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
            List<OpenStreetNote> fullObjects = new ArrayList<>();
            List<LatLon> fullObjectsLatLon = new ArrayList<>();
            List<LatLon> smallObjectsLatLon = new ArrayList<>();
            boolean showClosed = plugin.SHOW_CLOSED_OSM_BUGS.get();
            for (OpenStreetNote o : objects) {
                if (!o.isOpened() && !showClosed) {
                    continue;
                }
                float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
                float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
                if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
                    int backgroundColorRes;
                    if (o.isOpened()) {
                        backgroundColorRes = R.color.osm_bug_unresolved_icon_color;
                    } else {
                        backgroundColorRes = R.color.osm_bug_resolved_icon_color;
                    }
                    PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(ctx, ContextCompat.getColor(ctx, backgroundColorRes), true, false, DEFAULT_UI_ICON_ID, BackgroundType.COMMENT);
                    pointImageDrawable.drawSmallPoint(canvas, x, y, textScale);
                } else {
                    fullObjects.add(o);
                    fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
                }
            }
            for (OpenStreetNote o : fullObjects) {
                if (!o.isOpened() && !showClosed) {
                    continue;
                }
                float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
                float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
                int iconId;
                int backgroundColorRes;
                if (o.isOpened()) {
                    iconId = R.drawable.mx_special_symbol_remove;
                    backgroundColorRes = R.color.osm_bug_unresolved_icon_color;
                } else {
                    iconId = R.drawable.mx_special_symbol_check_mark;
                    backgroundColorRes = R.color.osm_bug_resolved_icon_color;
                }
                BackgroundType backgroundType = BackgroundType.COMMENT;
                PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(ctx, ContextCompat.getColor(ctx, backgroundColorRes), true, false, iconId, backgroundType);
                int offsetY = backgroundType.getOffsetY(ctx, textScale);
                pointImageDrawable.drawPoint(canvas, x, y - offsetY, textScale, false);
            }
            this.fullObjectsLatLon = fullObjectsLatLon;
            this.smallObjectsLatLon = smallObjectsLatLon;
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) PointImageDrawable(net.osmand.plus.views.PointImageDrawable) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) LatLon(net.osmand.data.LatLon) BackgroundType(net.osmand.data.FavouritePoint.BackgroundType)

Example 2 with PointImageDrawable

use of net.osmand.plus.views.PointImageDrawable in project Osmand by osmandapp.

the class FavouritesLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    cache.clear();
    if (this.settings.SHOW_FAVORITES.get() && favouritesHelper.isFavoritesLoaded()) {
        if (tileBox.getZoom() >= START_ZOOM) {
            float textScale = getTextScale();
            float iconSize = getIconSize(view.getApplication());
            QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
            // request to load
            final QuadRect latLonBounds = tileBox.getLatLonBounds();
            List<LatLon> fullObjectsLatLon = new ArrayList<>();
            List<LatLon> smallObjectsLatLon = new ArrayList<>();
            for (FavoriteGroup group : favouritesHelper.getFavoriteGroups()) {
                List<Pair<FavouritePoint, MapMarker>> fullObjects = new ArrayList<>();
                boolean synced = isSynced(group);
                for (FavouritePoint favoritePoint : group.getPoints()) {
                    double lat = favoritePoint.getLatitude();
                    double lon = favoritePoint.getLongitude();
                    if (favoritePoint.isVisible() && favoritePoint != contextMenuLayer.getMoveableObject() && lat >= latLonBounds.bottom && lat <= latLonBounds.top && lon >= latLonBounds.left && lon <= latLonBounds.right) {
                        MapMarker marker = null;
                        if (synced) {
                            marker = mapMarkersHelper.getMapMarker(favoritePoint);
                            if (marker == null || marker.history && !view.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
                                continue;
                            }
                        }
                        cache.add(favoritePoint);
                        float x = tileBox.getPixXFromLatLon(lat, lon);
                        float y = tileBox.getPixYFromLatLon(lat, lon);
                        if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
                            @ColorInt int color;
                            if (marker != null && marker.history) {
                                color = grayColor;
                            } else {
                                color = favouritesHelper.getColorWithCategory(favoritePoint, defaultColor);
                            }
                            PointImageDrawable pointImageDrawable = PointImageDrawable.getFromFavorite(view.getContext(), color, true, favoritePoint);
                            pointImageDrawable.drawSmallPoint(canvas, x, y, textScale);
                            smallObjectsLatLon.add(new LatLon(lat, lon));
                        } else {
                            fullObjects.add(new Pair<>(favoritePoint, marker));
                            fullObjectsLatLon.add(new LatLon(lat, lon));
                        }
                    }
                }
                for (Pair<FavouritePoint, MapMarker> pair : fullObjects) {
                    FavouritePoint favoritePoint = pair.first;
                    float x = tileBox.getPixXFromLatLon(favoritePoint.getLatitude(), favoritePoint.getLongitude());
                    float y = tileBox.getPixYFromLatLon(favoritePoint.getLatitude(), favoritePoint.getLongitude());
                    drawBigPoint(canvas, favoritePoint, x, y, pair.second, textScale);
                }
            }
            this.fullObjectsLatLon = fullObjectsLatLon;
            this.smallObjectsLatLon = smallObjectsLatLon;
        }
    }
    if (isTextVisible()) {
        textLayer.putData(this, cache);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.mapmarkers.MapMarker) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) PointImageDrawable(net.osmand.plus.views.PointImageDrawable) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) ColorInt(androidx.annotation.ColorInt) Pair(android.util.Pair)

Example 3 with PointImageDrawable

use of net.osmand.plus.views.PointImageDrawable in project Osmand by osmandapp.

the class OsmEditsLayer method drawPoint.

private void drawPoint(Canvas canvas, OsmPoint osmPoint, float x, float y) {
    float textScale = getTextScale();
    int iconId = getIconId(osmPoint);
    BackgroundType backgroundType = DEFAULT_BACKGROUND_TYPE;
    if (osmPoint.getGroup() == OsmPoint.Group.BUG) {
        backgroundType = BackgroundType.COMMENT;
    }
    PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(ctx, ContextCompat.getColor(ctx, R.color.created_poi_icon_color), true, false, iconId, backgroundType);
    pointImageDrawable.setAlpha(0.8f);
    int offsetY = backgroundType.getOffsetY(ctx, textScale);
    pointImageDrawable.drawPoint(canvas, x, y - offsetY, textScale, false);
}
Also used : BackgroundType(net.osmand.data.FavouritePoint.BackgroundType) PointImageDrawable(net.osmand.plus.views.PointImageDrawable) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)

Example 4 with PointImageDrawable

use of net.osmand.plus.views.PointImageDrawable in project Osmand by osmandapp.

the class TransportStopsLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
    List<TransportStop> objects = null;
    boolean nightMode = settings.isNightMode();
    OsmandApplication app = getApplication();
    if (tb.getZoom() >= startZoomRoute) {
        if (stopRoute != null) {
            objects = stopRoute.route.getForwardStops();
            int color = stopRoute.getColor(app, nightMode);
            attrs.paint.setColor(color);
            attrs.updatePaints(view.getApplication(), settings, tb);
            try {
                path.reset();
                List<Way> ws = stopRoute.route.getForwardWays();
                if (ws != null) {
                    for (Way w : ws) {
                        List<Float> tx = new ArrayList<>();
                        List<Float> ty = new ArrayList<>();
                        for (int i = 0; i < w.getNodes().size(); i++) {
                            Node o = w.getNodes().get(i);
                            float x = tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
                            float y = tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
                            tx.add(x);
                            ty.add(y);
                        }
                        GeometryWay.calculatePath(tb, tx, ty, path);
                    }
                }
                attrs.drawPath(canvas, path);
            } catch (Exception e) {
            // ignore
            }
        }
    }
    if (showTransportStops.get() && tb.getZoom() >= startZoom && objects == null) {
        data.queryNewData(tb);
        objects = data.getResults();
    }
    if (objects != null) {
        Context ctx = getContext();
        float textScale = getTextScale();
        float iconSize = getIconSize(app);
        QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb);
        List<TransportStop> fullObjects = new ArrayList<>();
        for (TransportStop o : objects) {
            float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
            float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
            if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
                PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(ctx, ContextCompat.getColor(ctx, R.color.transport_stop_icon_background), true, false, 0, BackgroundType.SQUARE);
                pointImageDrawable.setAlpha(0.9f);
                pointImageDrawable.drawSmallPoint(canvas, x, y, textScale);
            } else {
                fullObjects.add(o);
            }
        }
        for (TransportStop o : fullObjects) {
            float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
            float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
            if (stopRoute != null) {
                TransportStopType type = TransportStopType.findType(stopRoute.route.getType());
                if (type != null) {
                    drawPoint(canvas, textScale, x, y, RenderingIcons.getResId(type.getResName()));
                }
            } else {
                drawPoint(canvas, textScale, x, y, R.drawable.mx_highway_bus_stop);
            }
        }
    }
}
Also used : Context(android.content.Context) TransportStopType(net.osmand.plus.transport.TransportStopType) OsmandApplication(net.osmand.plus.OsmandApplication) Node(net.osmand.osm.edit.Node) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) PointImageDrawable(net.osmand.plus.views.PointImageDrawable) GeometryWay(net.osmand.plus.views.layers.geometry.GeometryWay) Way(net.osmand.osm.edit.Way) IOException(java.io.IOException) TransportStop(net.osmand.data.TransportStop)

Example 5 with PointImageDrawable

use of net.osmand.plus.views.PointImageDrawable in project Osmand by osmandapp.

the class AudioNotesLayer method drawRecording.

private void drawRecording(Canvas canvas, Recording o, float x, float y, float textScale) {
    int iconId;
    if (o.isPhoto()) {
        iconId = R.drawable.mx_special_photo_camera;
    } else if (o.isAudio()) {
        iconId = R.drawable.mx_special_microphone;
    } else {
        iconId = R.drawable.mx_special_video_camera;
    }
    PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(ctx, ContextCompat.getColor(ctx, R.color.audio_video_icon_color), true, iconId);
    pointImageDrawable.setAlpha(0.8f);
    pointImageDrawable.drawPoint(canvas, x, y, textScale, false);
}
Also used : PointImageDrawable(net.osmand.plus.views.PointImageDrawable)

Aggregations

PointImageDrawable (net.osmand.plus.views.PointImageDrawable)11 ArrayList (java.util.ArrayList)6 QuadRect (net.osmand.data.QuadRect)6 LatLon (net.osmand.data.LatLon)5 OsmandApplication (net.osmand.plus.OsmandApplication)3 Paint (android.graphics.Paint)2 Pair (android.util.Pair)2 ColorInt (androidx.annotation.ColorInt)2 BackgroundType (net.osmand.data.FavouritePoint.BackgroundType)2 SelectedGpxPoint (net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint)2 MapMarker (net.osmand.plus.mapmarkers.MapMarker)2 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)2 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)2 Context (android.content.Context)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 WptPt (net.osmand.GPXUtilities.WptPt)1 Amenity (net.osmand.data.Amenity)1 FavouritePoint (net.osmand.data.FavouritePoint)1 TransportStop (net.osmand.data.TransportStop)1