我正在使用自定义Overlay
类在MapView
窗口小部件上显示标记。我正在使用我发现的另一个例子中的相同图像,但我的叠加层却没有阴影。
这是原作:
..这是我的:
阴影是如何产生的?这是draw
类的Overlay
方法中的另一个可绘制资源或一些技巧。感谢。
-
这是我的Overlay
课程:
public class Mappin extends com.google.android.maps.Overlay {
private final GeoPoint geoPoint;
private final Context ctxContext;
public Mappin(Context ctxContext, GeoPoint geoPoint) {
super();
this.geoPoint = geoPoint;
this.ctxContext = ctxContext;
}
public boolean draw(Canvas canCanvas, MapView mvwMap, boolean booShadow, long lngWhen) {
super.draw(canCanvas, mvwMap, booShadow);
Point screenPts = new Point();
mvwMap.getProjection().toPixels(this.geoPoint, screenPts);
Bitmap bmp = BitmapFactory.decodeResource(this.ctxContext.getResources(), R.drawable.ic_location_marker);
canCanvas.drawBitmap(bmp, screenPts.x - bmp.getWidth() / 2, screenPts.y - bmp.getHeight(), null);
return true;
}
}
答案 0 :(得分:0)
我发现了一些显示标记阴影的代码。我需要调整偏斜因素才能使它工作,但它现在已经成功了。以下是我的自定义Overlay
的完整代码:
public class Mappin extends Overlay {
protected Drawable drwMarker;
protected GeoPoint gptCoordinates;
public Mappin(Drawable drwMarker, GeoPoint gptCoordinates) {
this.drwMarker = drwMarker;
this.gptCoordinates = gptCoordinates;
}
@Override
public void draw(Canvas canCanvas, MapView mapView, boolean booShadow) {
super.draw(canCanvas, mapView, booShadow);
Projection prjProjection = mapView.getProjection();
Integer x;
Integer y;
if (!booShadow) {
x = prjProjection.toPixels(gptCoordinates, null).x - (drwMarker.getIntrinsicWidth() / 2);
y = prjProjection.toPixels(gptCoordinates, null).y - (drwMarker.getIntrinsicHeight());
} else {
Integer intSign = (SHADOW_X_SKEW > 0 ? 1 : -1);
Float fltScaler = 1.1F - Math.abs(SHADOW_X_SKEW);
x = (int) (prjProjection.toPixels(gptCoordinates, null).x - (intSign * (drwMarker.getIntrinsicWidth() * fltScaler)));
y = (int) (prjProjection.toPixels(gptCoordinates, null).y - (drwMarker.getIntrinsicHeight() * SHADOW_Y_SCALE));
}
drawAt(canCanvas, drwMarker, x, y, booShadow);
}
}