Java Code Examples for org.osmdroid.views.overlay.Marker#setIcon()

The following examples show how to use org.osmdroid.views.overlay.Marker#setIcon() . 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: MapUtils.java    From AndroidApp with Mozilla Public License 2.0 7 votes vote down vote up
public static void addMarker(Context context, MapView map, Element element) {
    Marker marker = new Marker(map);
    marker.setPosition(new GeoPoint(element.lat, element.lon));
    marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    map.getOverlays().add(marker);
    map.invalidate();
    marker.setIcon(context.getResources().getDrawable(R.drawable.ic_location));

    marker.setTitle(String.valueOf(""));
    for (Map.Entry<String, String> tag : element.tags.entrySet()) {
        if (tag.getKey().equals("name")) {
            marker.setTitle(String.valueOf(tag.getValue()));
            break;
        }
    }
    if (marker.getTitle().equals(""))
        marker.setTitle(String.valueOf(element.id));

}
 
Example 2
Source File: OsmMapShapeConverter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * Add a LatLng to the map
 *
 * @param map
 * @param latLng
 * @param options
 * @return
 */
public static Marker addLatLngToMap(MapView map, GeoPoint latLng,
                                    MarkerOptions options) {
    Marker m = new Marker(map);
    m.setPosition(latLng);
    if (options!=null) {
        if (options.getIcon()!=null){
            m.setIcon(options.getIcon());
        }
        m.setAlpha(options.getAlpha());
        m.setTitle(options.getTitle());
        m.setSubDescription(options.getSubdescription());
        m.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, map));
    }
    map.getOverlayManager().add(m);
    return m;
}
 
Example 3
Source File: SampleSpeechBalloon.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
private void addToDisplay(final POI pPOI) {
    final Marker marker = new Marker(mMapView);
    marker.setTitle(pPOI.mTitle);
    marker.setPosition(pPOI.mGeoPoint);
    marker.setIcon(mBitmapDrawable);
    mMapView.getOverlays().add(marker);
    if (pPOI.mSpeechBalloon) {
        final SpeechBalloonOverlay speechBalloonOverlay = new SpeechBalloonOverlay();
        speechBalloonOverlay.setTitle(pPOI.mTitle);
        speechBalloonOverlay.setMargin(10);
        speechBalloonOverlay.setRadius(15);
        speechBalloonOverlay.setGeoPoint(new GeoPoint(pPOI.mGeoPoint));
        speechBalloonOverlay.setOffset(pPOI.mOffsetX, pPOI.mOffsetY);
        speechBalloonOverlay.setForeground(mForeground);
        speechBalloonOverlay.setBackground(mBackground);
        speechBalloonOverlay.setDragForeground(mDragForeground);
        speechBalloonOverlay.setDragBackground(mDragBackground);
        mMapView.getOverlays().add(speechBalloonOverlay);
    }
}
 
Example 4
Source File: IISTrackerBase.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
protected void addOverlays() {
    super.addOverlays();

    mMapView.setTilesScaledToDpi(true);
    mMapView.getController().setZoom(3);

    cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);

    image = getResources().getDrawable(R.drawable.sfppt);
    icon =getResources().getDrawable(R.drawable.sfppt_small);
    //icon_old=getResources().getDrawable(R.drawable.sfppt_small);
    //icon_old.setAlpha(77);

    marker = new Marker(mMapView);
    marker.setImage(image);
    marker.setIcon(icon);
    marker.setTitle("International Space Station");


}
 
Example 5
Source File: SampleMilitaryIconsMarker.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
private void addIcons(int count) {
     for (int i = 0; i < count; i++) {
          double random_lon = MapView.getTileSystem().getRandomLongitude(mRandom.nextDouble());
          double random_lat = MapView.getTileSystem().getRandomLatitude(mRandom.nextDouble());
          Marker m = new Marker(mMapView);
          m.setPosition(new GeoPoint(random_lat, random_lon));
          final int index = mRandom.nextInt(icons.size());
          m.setSnippet("A random point");
          m.setSubDescription("location: " + random_lat + "," + random_lon);
          m.setIcon(icons.get(index));
          mMapView.getOverlayManager().add(m);
     }

     mMapView.invalidate();
     Toast.makeText(getActivity(), count + " icons added! Current size: " + mMapView.getOverlayManager().size(), Toast.LENGTH_SHORT).show();

}
 
Example 6
Source File: PlacesOnMapActivity.java    From Travel-Mate with MIT License 6 votes vote down vote up
/**
 * Highlights the marker whose card is clicked
 *
 * @param title this is the title of the marker
 */
private void highlightMarker(String title) {
    int index = 0;
    Marker currentMarker = null;
    for (Marker m : mMarkerList) {
        if (m.getTitle().equals(title)) {
            currentMarker = mMarkerList.get(index);
            break;
        }
        index++;
    }
    if (mPreviousMarker != null) {
        mPreviousMarker.setIcon(mMarker);
        //hide info about previous marker
        mPreviousMarker.closeInfoWindow();
    }
    mMap.getOverlays().remove(currentMarker);
    mMap.invalidate();
    currentMarker.setIcon(mDefaultMarker);
    mMap.getOverlays().add(currentMarker);
    mMap.invalidate();
    //show info about current marker
    currentMarker.showInfoWindow();
    mPreviousMarker = currentMarker;
    zoomToMarker(currentMarker.getPosition().getLatitude(), currentMarker.getPosition().getLongitude());
}
 
Example 7
Source File: PlacesOnMapActivity.java    From Travel-Mate with MIT License 6 votes vote down vote up
/**
 * show marker
 *
 * @param locationLat  latitude
 * @param locationLong longitude
 * @param locationName name of location
 */
private void showMarker(Double locationLat, Double locationLong, String locationName) {
    GeoPoint coord = new GeoPoint(locationLat, locationLong);
    Marker marker = new Marker(mMap);
    if (ContextCompat.checkSelfPermission(PlacesOnMapActivity.this,
            Manifest.permission.ACCESS_COARSE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        marker.setPosition(coord);
        marker.setIcon(mMarker);
        marker.setTitle(locationName);
        marker.setOnMarkerClickListener(this);
        mMap.getOverlays().add(marker);
        mMap.invalidate();
        mMarkerList.add(marker);
    }
}
 
Example 8
Source File: MapViewRealTimeActivity.java    From Travel-Mate with MIT License 6 votes vote down vote up
/**
 * Sets marker at given location on map
 *
 * @param locationLat  latitude
 * @param locationLong longitude
 * @param locationName name of location
 * @param locationIcon icon
 */
private void showMarker(Double locationLat, Double locationLong, String locationName, Integer locationIcon) {
    GeoPoint coord = new GeoPoint(locationLat, locationLong);
    Marker marker = new Marker(mMap);

    if (ContextCompat.checkSelfPermission(MapViewRealTimeActivity.this,
            Manifest.permission.ACCESS_COARSE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        marker.setPosition(coord);
        marker.setIcon(this.getDrawable(locationIcon));
        marker.setTitle(locationName);
        marker.setOnMarkerClickListener(this);

        mMap.getOverlays().add(marker);
        mMap.invalidate();
    }
}
 
Example 9
Source File: MapUtils.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
public static Marker myLocation(Context context, MapView map, double latitude, double longitude) {
    if (map == null || context == null) return null;
    Marker marker = new Marker(map);
    marker.setPosition(new GeoPoint(latitude, longitude));
    marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    marker.setIcon(context.getResources().getDrawable(R.drawable.ic_gps_location));
    marker.setInfoWindow(null);
    map.getOverlays().add(marker);
    map.invalidate();
    return marker;
}
 
Example 10
Source File: MapUtils.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
public static Marker addMarker(Context context, MapView map, double latitude, double longitude) {
    if (map == null || context == null) return null;
    Marker marker = new Marker(map);
    marker.setPosition(new GeoPoint(latitude, longitude));
    marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    marker.setIcon(context.getResources().getDrawable(R.drawable.ic_location));
    marker.setInfoWindow(null);
    map.getOverlays().add(marker);
    map.invalidate();
    return marker;
}
 
Example 11
Source File: MapUtils.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
public static void addMarker(Context context, MapView map, double latitude, double longitude, String markerTitle) {
    Marker marker = new Marker(map);
    marker.setPosition(new GeoPoint(latitude, longitude));
    marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    map.getOverlays().add(marker);
    map.invalidate();
    marker.setIcon(context.getResources().getDrawable(R.drawable.ic_location));
    marker.setTitle(markerTitle);
}
 
Example 12
Source File: SampleCustomMyLocation.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void addOverlays() {
    super.addOverlays();
    myLocation = new Marker(mMapView);
    myLocation.setIcon(getResources().getDrawable(org.osmdroid.R.drawable.icon));
    myLocation.setImage(getResources().getDrawable(org.osmdroid.R.drawable.icon));


}
 
Example 13
Source File: IconPlottingOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {
    if (markerIcon != null) {
        GeoPoint pt = (GeoPoint) mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY(), null);
        /*
         * <b>Note</b></b: when plotting a point off the map, the conversion from
             * screen coordinates to map coordinates will return values that are invalid from a latitude,longitude
             * perspective. Sometimes this is a wanted behavior and sometimes it isn't. We are leaving it up to you,
             * the developer using osmdroid to decide on what is right for your application. See
             * <a href="https://github.com/osmdroid/osmdroid/pull/722">https://github.com/osmdroid/osmdroid/pull/722</a>
             * for more information and the discussion associated with this.
         */

        //just in case the point is off the map, let's fix the coordinates
        if (pt.getLongitude() < -180)
            pt.setLongitude(pt.getLongitude()+360);
        if (pt.getLongitude() > 180)
            pt.setLongitude(pt.getLongitude()-360);
        //latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
        if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude())
            pt.setLatitude(mapView.getTileSystem().getMaxLatitude());
        if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude())
            pt.setLatitude(mapView.getTileSystem().getMinLatitude());

        Marker m = new Marker(mapView);
        m.setPosition(pt);
        m.setIcon(markerIcon);
        m.setImage(markerIcon);
        m.setTitle("A demo title");
        m.setSubDescription("A demo sub description\n" + pt.getLatitude() + "," + pt.getLongitude());
        m.setSnippet("a snippet of information");
        mapView.getOverlayManager().add(m);
        mapView.invalidate();
        return true;
    }
    return false;
}
 
Example 14
Source File: MapUtils.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Add new {@link Marker} to {@link MapView}
 *
 * @param context  The context to use. Usually your {@link android.app.Application} or {@link android.app.Activity} object.
 * @param map      {@link MapView} to add marker on
 * @param position Location of the marker
 */
public static Marker addMarker(Context context, MapView map, GeoPoint position) {
    Marker marker = new Marker(map);
    marker.setPosition(position);
    marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    marker.setIcon(context.getResources().getDrawable(R.drawable.ic_location));
    marker.setTitle("Latitude: " + position.getLatitude() + "\n" + "Longitude: " + position.getLongitude());
    marker.setPanToView(true);
    marker.setDraggable(true);
    map.getOverlays().add(marker);
    map.invalidate();
    return marker;
}
 
Example 15
Source File: MilStdPointPlottingOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {
    if (def != null) {
        GeoPoint pt = (GeoPoint) mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY(), null);

        //just in case the point is off the map, let's fix the coordinates
        if (pt.getLongitude() < -180)
            pt.setLongitude(pt.getLongitude() + 360);
        if (pt.getLongitude() > 180)
            pt.setLongitude(pt.getLongitude() - 360);
        //latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
        if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude())
            pt.setLatitude(mapView.getTileSystem().getMaxLatitude());
        if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude())
            pt.setLatitude(mapView.getTileSystem().getMinLatitude());

        String code = def.getSymbolCode().replace("*", "-");
        //TODO if (!def.isMultiPoint())
        {
            int size = 128;

            SparseArray<String> attr = new SparseArray<>();
            attr.put(MilStdAttributes.PixelSize, size + "");

            ImageInfo ii = MilStdIconRenderer.getInstance().RenderIcon(code, def.getModifiers(), attr);
            Marker m = new Marker(mapView);
            m.setPosition(pt);
            m.setTitle(code);
            m.setSnippet(def.getDescription() + "\n" + def.getHierarchy());
            m.setSubDescription(def.getPath() + "\n" + m.getPosition().getLatitude() + "," + m.getPosition().getLongitude());

            if (ii != null && ii.getImage() != null) {
                BitmapDrawable d = new BitmapDrawable(ii.getImage());
                m.setImage(d);
                m.setIcon(d);

                int centerX = ii.getCenterPoint().x;    //pixel center position
                //calculate what percentage of the center this value is
                float realCenterX = (float) centerX / (float) ii.getImage().getWidth();

                int centerY = ii.getCenterPoint().y;
                float realCenterY = (float) centerY / (float) ii.getImage().getHeight();
                m.setAnchor(realCenterX, realCenterY);


                mapView.getOverlayManager().add(m);
                mapView.invalidate();
            }
        }

        return true;
    }
    return false;
}
 
Example 16
Source File: Plotter.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.radio_milstd2525b:
        case R.id.radio_milstd2525c:
            if (((RadioButton) v).isChecked()) {
                RendererSettings.getInstance().setSymbologyStandard(RendererSettings.Symbology_2525C);
            } else
                RendererSettings.getInstance().setSymbologyStandard(RendererSettings.Symbology_2525B);
            break;
        case R.id.cancelAddIcon:
            picker.dismiss();
            break;
        case R.id.addIcon:
            //from the menu, user entered code
            String code = symbolCode.getText().toString();
            int size = 128;
            try {
                size = Integer.parseInt(symbolSize.getText().toString());
            } catch (Exception ex) {
            }
            String baseCode = SymbolUtilities.getBasicSymbolID(code);
            SymbolDef def = SymbolDefTable.getInstance().getSymbolDef(baseCode, RendererSettings.getInstance().getSymbologyStandard());

            SparseArray<String> attr = new SparseArray<>();
            attr.put(MilStdAttributes.PixelSize, size + "");

            ImageInfo ii = mir.RenderIcon(code, new SparseArray<String>(), attr);
            Marker m = new Marker(mMapView);
            m.setPosition((GeoPoint) mMapView.getMapCenter());
            m.setTitle(code);
            if (def != null) {
                m.setSubDescription(def.getFullPath());
                m.setSnippet(def.getDescription() + "\n" + def.getHierarchy());
            }
            Drawable d = new BitmapDrawable(ii.getImage());
            m.setImage(d);
            m.setIcon(d);
            int centerX = ii.getCenterPoint().x;    //pixel center position
            //calculate what percentage of the center this value is
            float realCenterX = (float) centerX / (float) ii.getImage().getWidth();

            int centerY = ii.getCenterPoint().y;
            float realCenterY = (float) centerY / (float) ii.getImage().getHeight();
            m.setAnchor(realCenterX, realCenterY);
            mMapView.getOverlayManager().add(m);
            mMapView.invalidate();
            picker.dismiss();

            //TODO store the symbol code and size as an android preference
            SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
            edit.putString("MILSTDCODE", code);
            RendererSettings.getInstance().setDefaultPixelSize(size);
            edit.putInt("MILSTDSIZE", size);
            edit.commit();

            break;
        case R.id.enablePanning:
            enablePanning();

            break;
        case R.id.enablePainting:
            enablePainting();
            break;
    }
}
 
Example 17
Source File: SampleMapCenterOffset.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void addOverlays() {
	super.addOverlays();

	final Drawable drawable = getResources().getDrawable(R.drawable.marker_default);

	mList.add(new GeoPoint(38.8977, -77.0365));  // white house
	mList.add(new GeoPoint(38.8719, -77.0563));  // pentagon
	mList.add(new GeoPoint(38.8895, -77.0353));  // washington monument

	for (final GeoPoint geoPoint : mList) {
		final Marker startMarker = new Marker(mMapView);
		startMarker.setPosition(geoPoint);
		startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
		startMarker.setIcon(drawable);
		mMapView.getOverlays().add(startMarker);
	}

	mPaint.setColor(Color.RED);
	mPaint.setStrokeWidth(5);

	mMapView.getOverlays().add(new Overlay() {

		@Override
		public void draw(Canvas pCanvas, Projection pProjection) {
			mMapView.getProjection().save(pCanvas, false, true);
			final float centerX = pCanvas.getWidth() / 2f;
			final float centerY = pCanvas.getHeight() / 2f;
			pCanvas.drawLine(centerX, centerY, centerX + mOffsetX, centerY + mOffsetY, mPaint);
			mMapView.getProjection().restore(pCanvas, true);
		}
	});

	mMapView.setMapCenterOffset(mOffsetX, mOffsetY);
	mMapView.post(new Runnable() {
		@Override
		public void run() {
			show();
		}
	});
}