Search in sources :

Example 1 with OverlayItem

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

the class MapHelper method createOverlayItem.

/* Creates a marker overlay item */
private static OverlayItem createOverlayItem(Context context, Location location) {
    // create content of overlay item
    String time = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault()).format(location.getTime());
    final String title = context.getString(R.string.marker_description_source) + ": " + location.getProvider() + " | " + context.getString(R.string.marker_description_time) + ": " + time;
    final String description = context.getString(R.string.marker_description_accuracy) + ": " + location.getAccuracy();
    final GeoPoint position = new GeoPoint(location.getLatitude(), location.getLongitude());
    return new OverlayItem(title, description, position);
}
Also used : GeoPoint(org.osmdroid.util.GeoPoint) OverlayItem(org.osmdroid.views.overlay.OverlayItem)

Example 2 with OverlayItem

use of org.osmdroid.views.overlay.OverlayItem 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 3 with OverlayItem

use of org.osmdroid.views.overlay.OverlayItem in project open-event-android by fossasia.

the class OSMapFragment method populateMap.

private void populateMap() {
    if (!mayRequestStorageForOfflineMap())
        return;
    final MapView mapView = (MapView) rootView.findViewById(R.id.mapview);
    final ZoomControls zoomControls = (ZoomControls) rootView.findViewById(R.id.zoomControls);
    Resources resources = getContext().getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        zoomControls.setPadding(0, 0, 0, resources.getDimensionPixelSize(resourceId) + 4);
    }
    mapView.setBuiltInZoomControls(false);
    mapView.setMultiTouchControls(true);
    event = realmRepo.getEvent();
    event.addChangeListener(new RealmChangeListener<RealmModel>() {

        @Override
        public void onChange(RealmModel realmModel) {
            showEvent();
        }
    });
    GeoPoint geoPoint = new GeoPoint(getDestinationLatitude(), getDestinationLongitude());
    mapView.getController().setCenter(geoPoint);
    mapView.getController().setZoom(17);
    mapView.setMaxZoomLevel(20);
    mapView.setMinZoomLevel(3);
    OverlayItem position = new OverlayItem(getDestinationName(), "Location", geoPoint);
    zoomControls.setOnZoomInClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mapView.getController().zoomIn();
        }
    });
    zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mapView.getController().zoomOut();
        }
    });
    ArrayList<OverlayItem> items = new ArrayList<>();
    items.add(position);
    mapView.getOverlays().add(new ItemizedIconOverlay<>(items, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {

        @Override
        public boolean onItemSingleTapUp(int index, OverlayItem item) {
            return false;
        }

        @Override
        public boolean onItemLongPress(int index, OverlayItem item) {
            return false;
        }
    }, new DefaultResourceProxyImpl(getActivity())));
    mapView.invalidate();
}
Also used : ZoomControls(android.widget.ZoomControls) OverlayItem(org.osmdroid.views.overlay.OverlayItem) ArrayList(java.util.ArrayList) View(android.view.View) MapView(org.osmdroid.views.MapView) DefaultResourceProxyImpl(org.osmdroid.DefaultResourceProxyImpl) GeoPoint(org.osmdroid.util.GeoPoint) RealmModel(io.realm.RealmModel) GeoPoint(org.osmdroid.util.GeoPoint) MapView(org.osmdroid.views.MapView) Resources(android.content.res.Resources)

Example 4 with OverlayItem

use of org.osmdroid.views.overlay.OverlayItem 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

GeoPoint (org.osmdroid.util.GeoPoint)4 OverlayItem (org.osmdroid.views.overlay.OverlayItem)4 ArrayList (java.util.ArrayList)3 Drawable (android.graphics.drawable.Drawable)2 ItemizedIconOverlay (org.osmdroid.views.overlay.ItemizedIconOverlay)2 WayPoint (org.y20k.trackbook.core.WayPoint)2 Resources (android.content.res.Resources)1 View (android.view.View)1 ZoomControls (android.widget.ZoomControls)1 RealmModel (io.realm.RealmModel)1 DefaultResourceProxyImpl (org.osmdroid.DefaultResourceProxyImpl)1 MapView (org.osmdroid.views.MapView)1