Java Code Examples for org.osmdroid.views.MapView#LayoutParams

The following examples show how to use org.osmdroid.views.MapView#LayoutParams . 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: InfoWindow.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * open the InfoWindow at the specified GeoPosition + offset.
 * If it was already opened, close it before reopening.
 *
 * @param object   the graphical object on which is hooked the view
 * @param position to place the window on the map
 * @param offsetX  (&offsetY) the offset of the view to the position, in pixels.
 *                 This allows to offset the view from the object position.
 */
public void open(Object object, GeoPoint position, int offsetX, int offsetY) {
    close(); //if it was already opened
    mRelatedObject = object;
    mPosition = position;
    mOffsetX = offsetX;
    mOffsetY = offsetY;
    onOpen(object);
    MapView.LayoutParams lp = new MapView.LayoutParams(
        MapView.LayoutParams.WRAP_CONTENT,
        MapView.LayoutParams.WRAP_CONTENT,
        mPosition, MapView.LayoutParams.BOTTOM_CENTER,
        mOffsetX, mOffsetY);

    if (mMapView != null && mView != null) {
        mMapView.addView(mView, lp);
        mIsVisible = true;
    } else {
        Log.w(IMapView.LOGTAG, "Error trapped, InfoWindow.open mMapView: " + (mMapView == null ? "null" : "ok") + " mView: " + (mView == null ? "null" : "ok"));
    }
}
 
Example 2
Source File: InfoWindow.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * refresh the infowindow drawing. Must be called every time the view changes (drag, zoom,...).
 * Best practice is to call this method in the draw method of its overlay.
 */
public void draw(){
    if (!mIsVisible)
        return;
    try {
        MapView.LayoutParams lp = new MapView.LayoutParams(
                MapView.LayoutParams.WRAP_CONTENT,
                MapView.LayoutParams.WRAP_CONTENT,
                mPosition, MapView.LayoutParams.BOTTOM_CENTER,
                mOffsetX, mOffsetY);
        mMapView.updateViewLayout(mView, lp); // supposed to work only on the UI Thread
    } catch(Exception e) {
        if (MapSnapshot.isUIThread()) {
            throw e;
        }
        // in order to avoid a CalledFromWrongThreadException crash
    }
}
 
Example 3
Source File: SampleItemizedOverlay.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas c, MapView mapView, boolean shadow) {
	if (mFocusChanged) {
		mFocusChanged = false;

		// Remove any current focus
		if (mPopupView != null)
			mapView.removeView(mPopupView);

		SampleOverlayItem item = this.getFocus();
		if (item != null) {
			mPopupView = getPopupView(mapView.getContext(), item);
			MapView.LayoutParams lp = new MapView.LayoutParams(LayoutParams.WRAP_CONTENT,
					LayoutParams.WRAP_CONTENT, item.getPoint(),
					MapView.LayoutParams.TOP_CENTER, 0, 0);
			mapView.addView(mPopupView, lp);
		}
	}
	super.draw(c, mapView, shadow);
}
 
Example 4
Source File: OsmMarkerInfoWindow.java    From FancyPlaces with GNU General Public License v3.0 4 votes vote down vote up
public void open(Object object, GeoPoint position, int offsetX, int offsetY) {
    this.close();
    MapView.LayoutParams lp = new MapView.LayoutParams(-2, -2, position, 8, offsetX, offsetY);
    this.mMapView.addView(this.mView, lp);
    this.mIsVisible = true;
}