If you think the Android project SmartNavi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.osmdroid.bonuspack.overlays;
//www.java2s.comimport org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;
import org.osmdroid.views.overlay.Overlay;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
/**
* A ground overlay is an image that is fixed to a map.
* Mimics the GroundOverlay class from Google Maps Android API v2 as much as possible. Main differences:<br/>
* - Doesn't support: Z-Index, setPositionFromBounds<br/>
* - image can be any standard Android Drawable, instead of the BitmapDescriptor introduced in Maps API. <br/>
*
* @author M.Kergall
*
*/publicclass GroundOverlay extends Overlay {
protected Drawable mImage;
protected GeoPoint mPosition;
protectedfloat mBearing;
protectedfloat mWidth, mHeight;
protectedfloat mTransparency;
publicfinalstaticfloat NO_DIMENSION = -1.0f;
protected Point mPositionPixels, mSouthEastPixels;
public GroundOverlay(Context ctx) {
this(new DefaultResourceProxyImpl(ctx));
}
public GroundOverlay(final ResourceProxy resourceProxy) {
super(resourceProxy);
mWidth = 10.0f;
mHeight = NO_DIMENSION;
mBearing = 0.0f;
mTransparency = 0.0f;
mPositionPixels = new Point();
mSouthEastPixels = new Point();
}
publicvoid setImage(Drawable image){
mImage = image;
}
public Drawable getImage(){
return mImage;
}
public GeoPoint getPosition(){
return mPosition.clone();
}
publicvoid setPosition(GeoPoint position){
mPosition = position.clone();
}
publicfloat getBearing(){
return mBearing;
}
publicvoid setBearing(float bearing){
mBearing = bearing;
}
publicvoid setDimensions(float width){
mWidth = width;
mHeight = NO_DIMENSION;
}
publicvoid setDimensions(float width, float height){
mWidth = width;
mHeight = height;
}
publicfloat getHeight(){
return mHeight;
}
publicfloat getWidth(){
return mWidth;
}
publicvoid setTransparency(float transparency){
mTransparency = transparency;
}
publicfloat getTransparency(){
return mTransparency;
}
@Override protectedvoid draw(Canvas canvas, MapView mapView, boolean shadow) {
if (shadow)
return;
if (mImage == null)
return;
if (mHeight == NO_DIMENSION){
mHeight = mWidth * mImage.getIntrinsicHeight() / mImage.getIntrinsicWidth();
}
final Projection pj = mapView.getProjection();
pj.toPixels(mPosition, mPositionPixels);
GeoPoint pEast = mPosition.destinationPoint(mWidth, 90.0f);
GeoPoint pSouthEast = pEast.destinationPoint(mHeight, -180.0f);
pj.toPixels(pSouthEast, mSouthEastPixels);
int width = mSouthEastPixels.x-mPositionPixels.x;
int height = mSouthEastPixels.y-mPositionPixels.y;
mImage.setBounds(-width/2, -height/2, width/2, height/2);
mImage.setAlpha(255-(int)(mTransparency*255));
drawAt(canvas, mImage, mPositionPixels.x, mPositionPixels.y, false, -mBearing);
}
}