Java Code Examples for org.osmdroid.bonuspack.overlays.GroundOverlay

The following are top voted examples for showing how to use org.osmdroid.bonuspack.overlays.GroundOverlay. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: OPFMaps   File: ConvertUtils.java View source code 6 votes vote down vote up
@NonNull
public static GroundOverlay convertGroundOverlayOptions(@NonNull final Context context,
                                                        @NonNull final OPFGroundOverlayOptions options) {
    final GroundOverlay groundOverlay = new GroundOverlay(context);
    groundOverlay.setBearing(options.getBearing());
    groundOverlay.setTransparency(options.getTransparency());

    final OPFLatLngBounds bounds = options.getBounds();
    final OPFLatLng location = options.getLocation();

    if (location != null) {
        groundOverlay.setPosition(new GeoPoint(location.getLat(), location.getLng()));
    } else if (bounds != null) {
        final OPFLatLng boundsCenter = bounds.getCenter();
        groundOverlay.setPosition(new GeoPoint(boundsCenter.getLat(), boundsCenter.getLng()));
    } else {
        throw new IllegalArgumentException("no position in ground overlay options");
    }
    groundOverlay.setDimensions(options.getWidth(), options.getHeight());
    groundOverlay.setEnabled(options.isVisible());

    final OPFBitmapDescriptor opfBitmapDescriptor = options.getImage();
    if (opfBitmapDescriptor == null) {
        throw new IllegalArgumentException("no image in ground overlay options");
    }
    groundOverlay.setImage(((BitmapDescriptor) options.getImage()
            .getDelegate().getBitmapDescriptor()).createDrawable(context));

    return groundOverlay;
}
 
Example 2
Project: OPFMaps   File: OsmdroidMapDelegate.java View source code 6 votes vote down vote up
@NonNull
@Override
public OPFGroundOverlay addGroundOverlay(@NonNull final OPFGroundOverlayOptions options) {
    final GroundOverlay groundOverlay = ConvertUtils.convertGroundOverlayOptions(map.getContext(), options);
    map.getOverlays().add(groundOverlay);
    map.invalidate();
    return new OPFGroundOverlay(new OsmdroidGroundOverlayDelegate(map, groundOverlay));
}
 
Example 3
Project: OPFMaps   File: OsmdroidMapDelegate.java View source code 6 votes vote down vote up
@Override
public void clear() {
    final List<Overlay> overlays = map.getOverlays();

    for (Iterator<Overlay> it = overlays.iterator(); it.hasNext();) {
        final Overlay overlay = it.next();
        if (overlay instanceof Marker
                || overlay instanceof Polygon
                || overlay instanceof GroundOverlay
                || overlay instanceof Polyline) {
            it.remove();
        }
    }
    map.invalidate();
}
 
Example 4
Project: SmartNavi   File: KmlGroundOverlay.java View source code 6 votes vote down vote up
/** Constructs the KML feature from a GroundOverlay. */
public KmlGroundOverlay(GroundOverlay overlay){
	this();
	GeoPoint p = overlay.getPosition();
	GeoPoint pN = p.destinationPoint(overlay.getHeight()/2, 0.0f);
	GeoPoint pS = p.destinationPoint(overlay.getHeight()/2, 180.0f);
	GeoPoint pE = p.destinationPoint(overlay.getWidth()/2, 90.0f);
	GeoPoint pW = p.destinationPoint(overlay.getWidth()/2, -90.0f);
	mCoordinates = new ArrayList<GeoPoint>(2);
	mCoordinates.add(new GeoPoint(pN.getLatitudeE6(), pW.getLongitudeE6())); //NW
	mCoordinates.add(new GeoPoint(pS.getLatitudeE6(), pE.getLongitudeE6())); //SE
	//mIconHref = ???
	mIcon = ((BitmapDrawable)overlay.getImage()).getBitmap();
	mRotation = -overlay.getBearing();
	mColor = 255 - Color.alpha((int)(overlay.getTransparency()*255));
	mVisibility = overlay.isEnabled();
}
 
Example 5
Project: SmartNavi   File: KmlGroundOverlay.java View source code 6 votes vote down vote up
/** @return the corresponding GroundOverlay ready to display on the map */
@Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlDocument kmlDocument){
	Context context = map.getContext();
	GroundOverlay overlay = new GroundOverlay(context);
	if (mCoordinates.size()==2){
		GeoPoint pNW = mCoordinates.get(0);
		GeoPoint pSE = mCoordinates.get(1);
		overlay.setPosition(GeoPoint.fromCenterBetween(pNW, pSE));
		GeoPoint pNE = new GeoPoint(pNW.getLatitude(), pSE.getLongitude());
		int width = pNE.distanceTo(pNW);
		GeoPoint pSW = new GeoPoint(pSE.getLatitude(), pNW.getLongitude());
		int height = pSW.distanceTo(pNW);
		overlay.setDimensions((float)width, (float)height);
	}
	//TODO: 
	//else if size=4, nonrectangular quadrilateral
	//else, error
	
	if (mIcon != null)
		overlay.setImage(new BitmapDrawable(mIcon));
	else {
		/* TODO: currently filling the canvas. 
		ColorDrawable rect = new ColorDrawable(mColor);
		rect.setAlpha(255); //transparency will be applied below. 
		overlay.setImage(rect);
		*/
	}
	
	float transparency = 1.0f - Color.alpha(mColor)/255.0f; //KML transparency is the transparency part of the "color" element. 
	overlay.setTransparency(transparency);
	overlay.setBearing(-mRotation); //from KML counterclockwise to Google Maps API which is clockwise
	if (styler == null)
		overlay.setEnabled(mVisibility);
	else 
		styler.onFeature(overlay, this);
	return overlay;
}
 
Example 6
Project: SmartNavi   File: KmlFolder.java View source code 6 votes vote down vote up
/** 
 * Converts the overlay to a KmlFeature and add it inside this. 
 * Conversion from Overlay subclasses to KML Features is as follow: <br>
 *   FolderOverlay, MarkerClusterer => Folder<br>
 *   Marker => Point<br>
 *   Polygon => Polygon<br>
 *   Polyline => LineString<br>
 *   GroundOverlay => GroundOverlay<br>
 *   Else, add nothing. 
 * @param overlay to convert and add
 * @param kmlDoc for style handling. 
 * @return true if OK, false if the overlay has not been added. 
 */
public boolean addOverlay(Overlay overlay, KmlDocument kmlDoc){
	if (overlay == null)
		return false;
	KmlFeature kmlItem;
	if (overlay instanceof GroundOverlay){
		kmlItem = new KmlGroundOverlay((GroundOverlay)overlay);
	} else if (overlay instanceof FolderOverlay){
		kmlItem = new KmlFolder((FolderOverlay)overlay, kmlDoc);
	} else if (overlay instanceof MarkerClusterer){
		kmlItem = new KmlFolder((MarkerClusterer)overlay, kmlDoc);
	} else if (overlay instanceof Marker){
		Marker marker = (Marker)overlay;
		kmlItem = new KmlPlacemark(marker);
	} else if (overlay instanceof Polygon){
		Polygon polygon = (Polygon)overlay;
		kmlItem = new KmlPlacemark(polygon, kmlDoc);
	} else if (overlay instanceof Polyline){
		Polyline polyline = (Polyline)overlay;
		kmlItem = new KmlPlacemark(polyline, kmlDoc);
	} else {
		return false;
	}
	mItems.add(kmlItem);
	return true;
}
 
Example 7
Project: osmbonuspack   File: KmlGroundOverlay.java View source code 6 votes vote down vote up
/** Constructs the KML feature from a GroundOverlay. */
public KmlGroundOverlay(GroundOverlay overlay){
	this();
	GeoPoint p = overlay.getPosition();
	GeoPoint pN = p.destinationPoint(overlay.getHeight()/2, 0.0f);
	GeoPoint pS = p.destinationPoint(overlay.getHeight()/2, 180.0f);
	GeoPoint pE = p.destinationPoint(overlay.getWidth()/2, 90.0f);
	GeoPoint pW = p.destinationPoint(overlay.getWidth()/2, -90.0f);
	mCoordinates = new ArrayList<GeoPoint>(2);
	mCoordinates.add(new GeoPoint(pN.getLatitudeE6(), pW.getLongitudeE6())); //NW
	mCoordinates.add(new GeoPoint(pS.getLatitudeE6(), pE.getLongitudeE6())); //SE
	//mIconHref = ???
	mIcon = ((BitmapDrawable)overlay.getImage()).getBitmap();
	mRotation = -overlay.getBearing();
	mColor = 255 - Color.alpha((int)(overlay.getTransparency()*255));
	mVisibility = overlay.isEnabled();
}
 
Example 8
Project: osmbonuspack   File: KmlGroundOverlay.java View source code 6 votes vote down vote up
/** @return the corresponding GroundOverlay ready to display on the map */
@Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlDocument kmlDocument){
	Context context = map.getContext();
	GroundOverlay overlay = new GroundOverlay(context);
	if (mCoordinates.size()==2){
		GeoPoint pNW = mCoordinates.get(0);
		GeoPoint pSE = mCoordinates.get(1);
		overlay.setPosition(GeoPoint.fromCenterBetween(pNW, pSE));
		GeoPoint pNE = new GeoPoint(pNW.getLatitude(), pSE.getLongitude());
		int width = pNE.distanceTo(pNW);
		GeoPoint pSW = new GeoPoint(pSE.getLatitude(), pNW.getLongitude());
		int height = pSW.distanceTo(pNW);
		overlay.setDimensions((float)width, (float)height);
	}
	//TODO: else if size=4, nonrectangular quadrilateral
	
	if (mIcon != null){
		overlay.setImage(new BitmapDrawable(mIcon));
		//TODO: not clearly defined in KML spec, but color is supposed to be blended with the image. 
		float transparency = 1.0f - Color.alpha(mColor)/255.0f; //KML transparency is the transparency part of the "color" element. 
		overlay.setTransparency(transparency);
	} else {
		//when no image available, set it as a rectangle filled with the KML color
		Bitmap bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);
		bitmap.eraseColor(mColor);
		overlay.setImage(new BitmapDrawable(bitmap));
	}
	
	overlay.setBearing(-mRotation); //from KML counterclockwise to Google Maps API which is clockwise
	if (styler == null)
		overlay.setEnabled(mVisibility);
	else 
		styler.onFeature(overlay, this);
	return overlay;
}
 
Example 9
Project: osmbonuspack   File: KmlFolder.java View source code 6 votes vote down vote up
/** 
 * Converts the overlay to a KmlFeature and add it inside this. 
 * Conversion from Overlay subclasses to KML Features is as follow: <br>
 *   FolderOverlay, MarkerClusterer => Folder<br>
 *   Marker => Point<br>
 *   Polygon => Polygon<br>
 *   Polyline => LineString<br>
 *   GroundOverlay => GroundOverlay<br>
 *   Else, add nothing. 
 * @param overlay to convert and add
 * @param kmlDoc for style handling. 
 * @return true if OK, false if the overlay has not been added. 
 */
public boolean addOverlay(Overlay overlay, KmlDocument kmlDoc){
	if (overlay == null)
		return false;
	KmlFeature kmlItem;
	if (overlay instanceof GroundOverlay){
		kmlItem = new KmlGroundOverlay((GroundOverlay)overlay);
	} else if (overlay instanceof FolderOverlay){
		kmlItem = new KmlFolder((FolderOverlay)overlay, kmlDoc);
	} else if (overlay instanceof MarkerClusterer){
		kmlItem = new KmlFolder((MarkerClusterer)overlay, kmlDoc);
	} else if (overlay instanceof Marker){
		Marker marker = (Marker)overlay;
		kmlItem = new KmlPlacemark(marker);
	} else if (overlay instanceof Polygon){
		Polygon polygon = (Polygon)overlay;
		kmlItem = new KmlPlacemark(polygon, kmlDoc);
	} else if (overlay instanceof Polyline){
		Polyline polyline = (Polyline)overlay;
		kmlItem = new KmlPlacemark(polyline, kmlDoc);
	} else {
		return false;
	}
	mItems.add(kmlItem);
	return true;
}
 
Example 10
Project: osmbonuspack   File: MainActivity.java View source code 6 votes vote down vote up
@Override public boolean longPressHelper(GeoPoint p) {
	//Toast.makeText(this, "Long press", Toast.LENGTH_SHORT).show();
	//17. Using Polygon, defined as a circle:
	Polygon circle = new Polygon(this);
	circle.setPoints(Polygon.pointsAsCircle(p, 2000.0));
	circle.setFillColor(0x12121212);
	circle.setStrokeColor(Color.RED);
	circle.setStrokeWidth(2);
	map.getOverlays().add(circle);
	circle.setInfoWindow(new BasicInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, map));
	circle.setTitle("Centered on "+p.getLatitude()+","+p.getLongitude());
	
	//18. Using GroundOverlay
	GroundOverlay myGroundOverlay = new GroundOverlay(this);
	myGroundOverlay.setPosition(p);
	myGroundOverlay.setImage(getResources().getDrawable(R.drawable.ic_launcher).mutate());
	myGroundOverlay.setDimensions(2000.0f);
	//myGroundOverlay.setTransparency(0.25f);
	myGroundOverlay.setBearing(mGroundOverlayBearing);
	mGroundOverlayBearing += 20.0f;
	map.getOverlays().add(myGroundOverlay);
	
	map.invalidate();
	return true;
}