org.osmdroid.views.overlay.OverlayItem Java Examples

The following examples show how to use org.osmdroid.views.overlay.OverlayItem. 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: FragmentiGapMap.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
private void drawMark(final OverlayItem mapItem, final boolean hasComment, final long userIdR) {

        if (userIdR == 0) {
            return;
        }

        G.handler.post(new Runnable() {
            @Override
            public void run() {
                Marker marker = new Marker(map);
                marker.setPosition(new GeoPoint(mapItem.getPoint().getLatitude(), mapItem.getPoint().getLongitude()));
                InfoWindow infoWindow;
                marker.setIcon(avatarMark(userIdR, MarkerColor.GRAY));
                infoWindow = new MyInfoWindow(map, marker, userIdR, hasComment, FragmentiGapMap.this, G.fragmentActivity);
                marker.setInfoWindow(infoWindow);

                markers.add(marker);
                map.getOverlays().add(marker);
                map.invalidate();
            }
        });
    }
 
Example #3
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 #4
Source File: FragmentiGapMap.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
private void drawMark(MotionEvent motionEvent, MapView mapView) {
    Projection projection = mapView.getProjection();
    GeoPoint loc = (GeoPoint) projection.fromPixels((int) motionEvent.getX(), (int) motionEvent.getY());
    OverlayItem mapItem = new OverlayItem("", "", new GeoPoint((((double) loc.getLatitudeE6()) / 1000000), (((double) loc.getLongitudeE6()) / 1000000)));
    drawMark(mapItem, false, 0);
}
 
Example #5
Source File: FragmentiGapMap.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
private void drawMark(double latitude, double longitude, boolean hasComment, long userId) {
    OverlayItem mapItem = new OverlayItem("", "", new GeoPoint(latitude, longitude));
    drawMark(mapItem, hasComment, userId);
}
 
Example #6
Source File: FragmentiGapMap.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * ****************************** callbacks ******************************
 */

@Override
public void onLocationChanged(Location location) {
    this.location = location;

    if (firstEnter) {
        lastLatitude = location.getLatitude();
        lastLongitude = location.getLongitude();
        firstEnter = false;
        currentLocation(location, true);
        getCoordinateLoop(0, false);
        getDistanceLoop(0, false);
    }
    mapBounding(location);
    GeoPoint geoPoint = new GeoPoint(location.getLatitude(), location.getLongitude());
    OverlayItem overlayItem = new OverlayItem("title", "City", geoPoint);

    //Drawable drawable = context.getResources().getDrawable(R.drawable.location_current);
    overlayItem.setMarker(avatarMark(G.userId, MarkerColor.GRAY)); // marker color is not important in this line because for mineAvatar will be unused.

    ArrayList<OverlayItem> overlayItemArrayList = new ArrayList<>();
    overlayItemArrayList.add(overlayItem);
    ItemizedOverlay<OverlayItem> locationOverlay = new ItemizedIconOverlay<>(context, overlayItemArrayList, null);

    if (latestLocation != null) {
        map.getOverlays().remove(latestLocation);
    }

    latestLocation = locationOverlay;
    map.getOverlays().add(locationOverlay);

    //if (BuildConfig.DEBUG) {
    //    G.handler.post(new Runnable() {
    //        @Override
    //        public void run() {
    //            Toast.makeText(context, "Update Position", Toast.LENGTH_SHORT).show();
    //        }
    //    });
    //}
}
 
Example #7
Source File: PregrabActivity.java    From AppleWifiNlpBackend with Apache License 2.0 4 votes vote down vote up
@Override
protected OverlayItem createItem(int i) {
    return new OverlayItem(null, null, mapView.getMapCenter());
}
 
Example #8
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 #9
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 #10
Source File: SampleItemizedOverlayMultiClick.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
private void message(final OverlayItem pItem) {
	Toast.makeText(getActivity(), pItem.getTitle() + ": " + pItem.getSnippet(), Toast.LENGTH_LONG).show();
}
 
Example #11
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);
}
 
Example #12
Source File: SampleItemizedOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onFocusChanged(ItemizedOverlay<?> overlay, OverlayItem newFocus) {
	mFocusChanged = true;
}
 
Example #13
Source File: SampleAnimatedZoomToLocation.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void addOverlays() {
  super.addOverlays();

  final Context context = getActivity();
  Toast.makeText(getActivity(), "Make sure location services are enabled!", Toast.LENGTH_LONG).show();
  mGpsMyLocationProvider = new GpsMyLocationProvider(context);
  mGpsMyLocationProvider.startLocationProvider(new IMyLocationConsumer() {
    @Override
    public void onLocationChanged(Location location, IMyLocationProvider source) {
      mGpsMyLocationProvider.stopLocationProvider();
      if(mMyLocationOverlay == null) {
        final ArrayList<OverlayItem> items = new ArrayList<>();
        items.add(new OverlayItem("Me", "My Location",
          new GeoPoint(location)));

        mMyLocationOverlay = new ItemizedOverlayWithFocus<>(items,
              new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                @Override
                public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                  IMapController mapController = mMapView.getController();
                  mapController.setCenter(item.getPoint());
                  mapController.zoomTo(mMapView.getMaxZoomLevel());
                  return true;
                }

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

        mMyLocationOverlay.setFocusItemsOnTap(true);
        mMyLocationOverlay.setFocusedItem(0);

        mMapView.getOverlays().add(mMyLocationOverlay);

        mMapView.getController().setZoom(10);
        IGeoPoint geoPoint = mMyLocationOverlay.getFocusedItem().getPoint();
        mMapView.getController().animateTo(geoPoint);
      }
    }
  });

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

  MinimapOverlay miniMapOverlay = new MinimapOverlay(context,
    mMapView.getTileRequestCompleteHandler());
  mMapView.getOverlays().add(miniMapOverlay);
}
 
Example #14
Source File: Bug1322.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
private void message(final OverlayItem pItem) {
    Toast.makeText(getActivity(), pItem.getTitle() + ": " + pItem.getSnippet(), Toast.LENGTH_LONG).show();
}