Search in sources :

Example 1 with ItemizedIconOverlay

use of org.osmdroid.views.overlay.ItemizedIconOverlay in project trackbook by y20k.

the class MapHelper method createTrackOverlay.

/* Creates icon overlay for track */
public static ItemizedIconOverlay createTrackOverlay(final Context context, Track track, boolean trackingActive) {
    WayPoint wayPoint;
    boolean currentPosition;
    final int trackSize = track.getSize();
    final List<WayPoint> wayPoints = track.getWayPoints();
    final ArrayList<OverlayItem> overlayItems = new ArrayList<>();
    for (int i = 0; i < track.getSize(); i++) {
        // get WayPoint and check if it is current position
        wayPoint = wayPoints.get(i);
        currentPosition = i == trackSize - 1;
        // create marker
        Drawable newMarker;
        // CASE 1: Tracking active and WayPoint is not current position
        if (trackingActive && !currentPosition) {
            if (wayPoint.getIsStopOver()) {
                // stop over marker
                newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_crumb_grey_24dp);
            } else {
                // default marker for this case
                newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_crumb_red_24dp);
            }
        } else // CASE 2: Tracking active and WayPoint is current position
        if (trackingActive && currentPosition) {
            if (wayPoint.getIsStopOver()) {
                // stop over marker
                newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_grey_24dp);
            } else {
                // default marker for this case
                newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_red_24dp);
            }
        } else // CASE 3: Tracking not active and WayPoint is not current position
        if (!trackingActive && !currentPosition) {
            if (wayPoint.getIsStopOver()) {
                // stop over marker
                newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_crumb_grey_24dp);
            } else {
                // default marker for this case
                newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_crumb_blue_24dp);
            }
        } else // CASE 4: Tracking not active and WayPoint is current position
        {
            // default marker
            newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_crumb_blue_24dp);
        }
        // create overlay item
        OverlayItem overlayItem = createOverlayItem(context, wayPoint.getLocation());
        overlayItem.setMarker(newMarker);
        // add marker to list of overlay items
        overlayItems.add(overlayItem);
    }
    // return overlay for current position
    return new ItemizedIconOverlay<>(overlayItems, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {

        @Override
        public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
            // tap on waypoint
            Toast.makeText(context, item.getTitle(), Toast.LENGTH_LONG).show();
            return true;
        }

        @Override
        public boolean onItemLongPress(final int index, final OverlayItem item) {
            // long press on waypoint
            Toast.makeText(context, item.getSnippet(), Toast.LENGTH_LONG).show();
            return true;
        }
    }, context);
}
Also used : OverlayItem(org.osmdroid.views.overlay.OverlayItem) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) WayPoint(org.y20k.trackbook.core.WayPoint) ItemizedIconOverlay(org.osmdroid.views.overlay.ItemizedIconOverlay) WayPoint(org.y20k.trackbook.core.WayPoint) GeoPoint(org.osmdroid.util.GeoPoint)

Example 2 with ItemizedIconOverlay

use of org.osmdroid.views.overlay.ItemizedIconOverlay in project trackbook by y20k.

the class MapHelper method createMyLocationOverlay.

/* Creates icon overlay for current position (used in MainActivity Fragment) */
public static ItemizedIconOverlay createMyLocationOverlay(final Context context, Location currentBestLocation, boolean locationIsNew) {
    final ArrayList<OverlayItem> overlayItems = new ArrayList<>();
    // create marker
    Drawable newMarker;
    if (locationIsNew) {
        newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_blue_24dp);
    } else {
        newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_grey_24dp);
    }
    OverlayItem overlayItem = createOverlayItem(context, currentBestLocation);
    overlayItem.setMarker(newMarker);
    // add marker to list of overlay items
    overlayItems.add(overlayItem);
    // create and return overlay for current position
    return new ItemizedIconOverlay<>(overlayItems, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {

        @Override
        public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
            // tap on My Location dot icon
            Toast.makeText(context, item.getTitle() + " | " + item.getSnippet(), Toast.LENGTH_LONG).show();
            return true;
        }

        @Override
        public boolean onItemLongPress(final int index, final OverlayItem item) {
            // long press on My Location dot icon
            return true;
        }
    }, context);
}
Also used : OverlayItem(org.osmdroid.views.overlay.OverlayItem) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) ItemizedIconOverlay(org.osmdroid.views.overlay.ItemizedIconOverlay) WayPoint(org.y20k.trackbook.core.WayPoint) GeoPoint(org.osmdroid.util.GeoPoint)

Aggregations

Drawable (android.graphics.drawable.Drawable)2 ArrayList (java.util.ArrayList)2 GeoPoint (org.osmdroid.util.GeoPoint)2 ItemizedIconOverlay (org.osmdroid.views.overlay.ItemizedIconOverlay)2 OverlayItem (org.osmdroid.views.overlay.OverlayItem)2 WayPoint (org.y20k.trackbook.core.WayPoint)2