Permalink
Browse files

Merge pull request #1262 from osmdroid/bug/#1122

bug/#1122 - removed confusion about long press in itemized overlay samples
  • Loading branch information...
monsieurtanuki committed Feb 4, 2019
2 parents b9054a0 + d2147f7 commit c62232573995abf53e90a84388367d25c907be04
@@ -41,8 +41,6 @@
// Fields
// ===========================================================
private ItemizedOverlayWithFocus<OverlayItem> itemOverlay;
private RotationGestureOverlay mRotationGestureOverlay;
private OverlayItem overlayItem;
private List<Drawable> icons = new ArrayList<>(4);

@Override
@@ -86,7 +84,7 @@ public boolean onItemLongPress(final int index, final OverlayItem item) {
context,
"Item '" + item.getTitle() + "' (index=" + index
+ ") got long pressed", Toast.LENGTH_LONG).show();
return false;
return true;
}
}, context);
itemOverlay.setFocusItemsOnTap(true);
@@ -97,6 +95,7 @@ public boolean onItemLongPress(final int index, final OverlayItem item) {

mMapView.getOverlays().add(itemOverlay);

final RotationGestureOverlay mRotationGestureOverlay;
mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
mRotationGestureOverlay.setEnabled(false);
mMapView.getOverlays().add(mRotationGestureOverlay);
@@ -110,7 +109,7 @@ public boolean onItemLongPress(final int index, final OverlayItem item) {
}

// Zoom and center on the focused item.
mMapView.getController().setZoom(3);
mMapView.getController().setZoom(3.);
IGeoPoint geoPoint = itemOverlay.getFocusedItem().getPoint();
mMapView.getController().animateTo(geoPoint);

@@ -170,6 +169,7 @@ private void addIcons(int count) {
for (int i = 0; i < count; i++) {
double random_lon = (Math.random() * 360) - 180;
double random_lat = (Math.random() * 180) - 90;
final OverlayItem overlayItem;
overlayItem = new OverlayItem("A random point", "SampleDescription", new GeoPoint(random_lat,
random_lon));
int index = (int) (Math.random() * (icons.size()));
@@ -41,9 +41,6 @@
// Fields
// ===========================================================

private ItemizedOverlayWithFocus<OverlayItem> mMyLocationOverlay;
private RotationGestureOverlay mRotationGestureOverlay;

@Override
public String getSampleTitle() {
return TITLE;
@@ -65,6 +62,7 @@ protected void addOverlays() {
final Context context = getActivity();

/* Itemized Overlay */
final ItemizedOverlayWithFocus<OverlayItem> mMyLocationOverlay;
{
/* Create a static ItemizedOverlay showing some Markers on various cities. */
final ArrayList<OverlayItem> items = new ArrayList<>();
@@ -97,7 +95,7 @@ public boolean onItemLongPress(final int index, final OverlayItem item) {
context,
"Item '" + item.getTitle() + "' (index=" + index
+ ") got long pressed", Toast.LENGTH_LONG).show();
return false;
return true;
}
}, context);
mMyLocationOverlay.setFocusItemsOnTap(true);
@@ -111,6 +109,7 @@ public boolean onItemLongPress(final int index, final OverlayItem item) {

mMapView.getOverlays().add(mMyLocationOverlay);

final RotationGestureOverlay mRotationGestureOverlay;
mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
mRotationGestureOverlay.setEnabled(false);
mMapView.getOverlays().add(mRotationGestureOverlay);
@@ -4,6 +4,7 @@
import java.util.ArrayList;

import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;
import org.osmdroid.api.IGeoPoint;
import org.osmdroid.util.GeoPoint;
@@ -38,9 +39,6 @@
// Fields
// ===========================================================

private ItemizedOverlayWithFocus<OverlayItem> iconOverlay;
private RotationGestureOverlay mRotationGestureOverlay;

@Override
public String getSampleTitle() {
return TITLE;
@@ -59,23 +57,24 @@ protected void addOverlays() {
final Context context = getActivity();

/* Itemized Overlay */
final ItemizedOverlayWithFocus<OverlayItem> iconOverlay;
{
/* Create a static ItemizedOverlay showing some Markers on various cities. */
final ArrayList<OverlayItem> items = new ArrayList<>();
for (int i=0; i < 5000; i++){
double random_lon=(Math.random() * 360) -180;
double random_lat = (Math.random() * 180) - 90;
double random_lon= MapView.getTileSystem().getRandomLongitude(Math.random());
double random_lat = MapView.getTileSystem().getRandomLatitude(Math.random());
items.add(new OverlayItem("A random point", "SampleDescription", new GeoPoint(random_lat,
random_lon)));
}
items.add(new OverlayItem("Berlin", "This is a relatively short SampleDescription.",
new GeoPoint(52518333, 13408333))); // Berlin
new GeoPoint(52.518333, 13.408333))); // Berlin
items.add(new OverlayItem(
"Washington",
"This SampleDescription is a pretty long one. Almost as long as a the great wall in china.",
new GeoPoint(38895000, -77036667))); // Washington
items.add(new OverlayItem("San Francisco", "SampleDescription", new GeoPoint(37779300,
-122419200))); // San Francisco
new GeoPoint(38.895000, -77.036667))); // Washington
items.add(new OverlayItem("San Francisco", "SampleDescription", new GeoPoint(37.779300,
-122.419200))); // San Francisco

/* OnTapListener for the Markers, shows a simple Toast. */
iconOverlay = new ItemizedOverlayWithFocus<>(items,
@@ -95,14 +94,15 @@ public boolean onItemLongPress(final int index, final OverlayItem item) {
context,
"Item '" + item.getTitle() + "' (index=" + index
+ ") got long pressed", Toast.LENGTH_LONG).show();
return false;
return true;
}
}, context);
iconOverlay.setFocusItemsOnTap(true);
iconOverlay.setFocusedItem(0);

mMapView.getOverlays().add(iconOverlay);

final RotationGestureOverlay mRotationGestureOverlay;
mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
mRotationGestureOverlay.setEnabled(false);
mMapView.getOverlays().add(mRotationGestureOverlay);
@@ -113,7 +113,7 @@ public boolean onItemLongPress(final int index, final OverlayItem item) {
mMapView.getOverlays().add(rotationGestureOverlay);

// Zoom and center on the focused item.
mMapView.getController().setZoom(5);
mMapView.getController().setZoom(5.);
IGeoPoint geoPoint = iconOverlay.getFocusedItem().getPoint();
mMapView.getController().animateTo(geoPoint);

@@ -87,7 +87,7 @@ public boolean onItemLongPress(final int index, final OverlayItem item) {
SampleWithMinimapItemizedoverlay.this,
"Item '" + item.getTitle() + "' (index=" + index
+ ") got long pressed", Toast.LENGTH_LONG).show();
return false;
return true;
}
}, getApplicationContext());
this.mMapView.getOverlays().add(this.mMyLocationOverlay);
@@ -134,7 +134,7 @@ public boolean longPressHelper(final GeoPoint p) {

// Default location and zoom level
IMapController mapController = mMapView.getController();
mapController.setZoom(5);
mapController.setZoom(5.);
GeoPoint startPoint = new GeoPoint(50.936255, 6.957779);
mapController.setCenter(startPoint);
}

0 comments on commit c622325

Please sign in to comment.