Java Code Examples for org.osmdroid.views.overlay.ItemizedIconOverlay#OnItemGestureListener

The following examples show how to use org.osmdroid.views.overlay.ItemizedIconOverlay#OnItemGestureListener . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OsmdroidMapWrapper.java    From osmdroid with Apache License 2.0 7 votes vote down vote up
@Override
public void addMarker(final Marker aMarker) {
	if (mItemizedOverlay == null) {
		// XXX this is a bit cumbersome. Maybe we should just do a simple ItemizedIconOverlay with null listener
		mItemizedOverlay = new ItemizedOverlayWithFocus<OverlayItem>(new ArrayList<OverlayItem>(), new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
			@Override
			public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
				return false;
			}

			@Override
			public boolean onItemLongPress(final int index, final OverlayItem item) {
				return false;
			}
		},this.mMapView.getContext());
		mItemizedOverlay.setFocusItemsOnTap(true);
		mMapView.getOverlays().add(mItemizedOverlay);
	}
	final OverlayItem item = new OverlayItem(aMarker.title, aMarker.snippet, new GeoPoint(aMarker.latitude, aMarker.longitude));
	if (aMarker.bitmap != null) {
		item.setMarker(new BitmapDrawable(mMapView.getResources(), aMarker.bitmap));
	} else {
		if (aMarker.icon != 0) {
			item.setMarker(mMapView.getResources().getDrawable(aMarker.icon));
		}
	}
	if (aMarker.anchor == Marker.Anchor.CENTER) {
		item.setMarkerHotspot(OverlayItem.HotspotPlace.CENTER);
	}
	mItemizedOverlay.addItem(item);
}
 
Example 2
Source File: PMap.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
public PMap(AppRunner appRunner) {
    super(appRunner.getAppContext());

    mAppRunner = appRunner;
    this.mContext = appRunner.getAppContext();
    // super(appRunner, pixelTileSize);
    Configuration.getInstance().setUserAgentValue(this.mContext.getApplicationContext().getPackageName());

    // Create the mapview with the custom tile provider array
    this.mapView = this;
    mapView.setTileSource(TileSourceFactory.MAPNIK);
    mapView.setTilesScaledToDpi(true);
    mapView.setBuiltInZoomControls(false);
    mapView.setMultiTouchControls(true);
    mapView.setUseDataConnection(true);
    mapView.setClickable(true);
    mapView.setFocusable(true);
    mapView.setDuplicateParentStateEnabled(false);

    mapController = mapView.getController();

    /*
    mapView.setMapListener(new DelayedMapListener(new MapListener() {
        @Override
        public boolean onZoom(final ZoomEvent e) {
            // do something
            MLog.d("map", "zoom " + e.getZoomLevel());
            return true;
        }

        @Override
        public boolean onScroll(final ScrollEvent e) {
            Log.i("zoom", e.getX() + " " + e.getY());
            return true;
        }
    }, 1000));
    */

    markerList = new ArrayList<OverlayItem>();

    Drawable icon = mContext.getResources().getDrawable(R.drawable.icon);
    iconOverlay = new ItemizedOverlayWithFocus<OverlayItem>(markerList,
            new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                @Override
                public boolean onItemLongPress(int arg0, OverlayItem arg1) {
                    MLog.d(TAG, "long press");
                    return false;
                }

                @Override
                public boolean onItemSingleTapUp(int arg0, OverlayItem arg1) {
                    MLog.d(TAG, "single press");

                    // new InfoWindow()

                    return true;
                }
            }, getContext());


    iconOverlay.setFocusItemsOnTap(true);


    // myLocationOverlay = new MyLocationNewOverlay(mContext, mapView);
    // mapView.getOverlays().add(myLocationOverlay);
    mapView.getOverlays().add(iconOverlay);

    /*
    mapView.setMapListener(new DelayedMapListener(new MapListener() {
        @Override
        public boolean onScroll(ScrollEvent event) {
            //Log.d(TAG, "qqqqqq");

            //mapView.getBoundingBox().getCenter();

            return true;
        }

        @Override
        public boolean onZoom(ZoomEvent event) {
            //Log.d(TAG, "qqqqqq");

            //mapView.getBoundingBox().getCenter();


            return true;
        }
    }, 500));
    */

    // myLocationOverlay.enableMyLocation();
    // myLocationOverlay.setDrawAccuracyEnabled(true);

}
 
Example 3
Source File: SampleMilitaryIconsItemizedIcons.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void addOverlays() {
     super.addOverlays();

     final Context context = getActivity();


     icons.add(getResources().getDrawable(org.osmdroid.R.drawable.sfgpuci));
     icons.add(getResources().getDrawable(org.osmdroid.R.drawable.shgpuci));
     icons.add(getResources().getDrawable(org.osmdroid.R.drawable.sngpuci));
     icons.add(getResources().getDrawable(org.osmdroid.R.drawable.sugpuci));

     /* Itemized Overlay */
     {
          /* OnTapListener for the Markers, shows a simple Toast. */
          itemOverlay = new ItemizedOverlayWithFocus<>(new ArrayList<OverlayItem>(),
                  new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                       @Override
                       public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                            Toast.makeText(
                                    context,
                                    "Item '" + item.getTitle() + "' (index=" + index
                                            + ") got single tapped up", Toast.LENGTH_LONG).show();
                            return true;
                       }

                       @Override
                       public boolean onItemLongPress(final int index, final OverlayItem item) {
                            Toast.makeText(
                                    context,
                                    "Item '" + item.getTitle() + "' (index=" + index
                                            + ") got long pressed", Toast.LENGTH_LONG).show();
                            return true;
                       }
                  }, context);
          itemOverlay.setFocusItemsOnTap(true);
          itemOverlay.setFocusedItem(0);

          //generates 50 randomized points
          addIcons(50);

          mMapView.getOverlays().add(itemOverlay);

          final RotationGestureOverlay mRotationGestureOverlay;
          mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
          mRotationGestureOverlay.setEnabled(false);
          mMapView.getOverlays().add(mRotationGestureOverlay);
     }

     /* MiniMap */
     {
    //      MinimapOverlay miniMapOverlay = new MinimapOverlay(context,
      //         mMapView.getTileRequestCompleteHandler());
        //  mMapView.getOverlays().add(miniMapOverlay);
     }

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

     setHasOptionsMenu(true);
     Toast.makeText(context, "Icon selection and location are random!", Toast.LENGTH_SHORT).show();
}
 
Example 4
Source File: SampleWithMinimapItemizedOverlayWithScale.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void addOverlays() {
	super.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= 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(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(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,
				new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
					@Override
					public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
						Toast.makeText(
								context,
								"Item '" + item.getTitle() + "' (index=" + index
										+ ") got single tapped up", Toast.LENGTH_LONG).show();
						return true;
					}

					@Override
					public boolean onItemLongPress(final int index, final OverlayItem item) {
						Toast.makeText(
								context,
								"Item '" + item.getTitle() + "' (index=" + index
										+ ") got long pressed", Toast.LENGTH_LONG).show();
						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);
	}

	final RotationGestureOverlay rotationGestureOverlay = new RotationGestureOverlay(mMapView);
	rotationGestureOverlay.setEnabled(true);
	mMapView.getOverlays().add(rotationGestureOverlay);

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

}
 
Example 5
Source File: SampleWithMinimapItemizedOverlayWithFocus.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void addOverlays() {
	super.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<>();
		items.add(new OverlayItem("Hannover", "Tiny SampleDescription", new GeoPoint(52.370816,
				9.735936))); // Hannover
		items.add(new OverlayItem("Berlin", "This is a relatively short SampleDescription.",
				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(38.895, -77.036667))); // Washington
		items.add(new OverlayItem("San Francisco", "SampleDescription", new GeoPoint(37.7793,
				-122.4192))); // San Francisco

		/* OnTapListener for the Markers, shows a simple Toast. */
		mMyLocationOverlay = new ItemizedOverlayWithFocus<>(items,
				new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
					@Override
					public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
						Toast.makeText(
								context,
								"Item '" + item.getTitle() + "' (index=" + index
										+ ") got single tapped up", Toast.LENGTH_LONG).show();
						return true;
					}

					@Override
					public boolean onItemLongPress(final int index, final OverlayItem item) {
						Toast.makeText(
								context,
								"Item '" + item.getTitle() + "' (index=" + index
										+ ") got long pressed", Toast.LENGTH_LONG).show();
						return true;
					}
				}, context);
		mMyLocationOverlay.setFocusItemsOnTap(true);
		mMyLocationOverlay.setFocusedItem(0);
		//https://github.com/osmdroid/osmdroid/issues/317
		//you can override the drawing characteristics with this
		mMyLocationOverlay.setMarkerBackgroundColor(Color.BLUE);
		mMyLocationOverlay.setMarkerTitleForegroundColor(Color.WHITE);
		mMyLocationOverlay.setMarkerDescriptionForegroundColor(Color.WHITE);
		mMyLocationOverlay.setDescriptionBoxPadding(15);

		mMapView.getOverlays().add(mMyLocationOverlay);

		final RotationGestureOverlay mRotationGestureOverlay;
		mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
		mRotationGestureOverlay.setEnabled(false);
		mMapView.getOverlays().add(mRotationGestureOverlay);
	}

	/* MiniMap */
	{
		MinimapOverlay miniMapOverlay = new MinimapOverlay(context,
				mMapView.getTileRequestCompleteHandler());
		mMapView.getOverlays().add(miniMapOverlay);
	}

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

	setHasOptionsMenu(true);
}