简体   繁体   中英

Android - How to add shadow in a custom MyLocationOverlay

I want to add a shadow to a custom marker for MyLocationOverlay. I have tried this using this question :

  @Override
  protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
    mapView.getProjection().toPixels(myLocation, currentPoint);
    canvas.drawBitmap(markerBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null);
  }

  @Override
  public synchronized boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {

      if (getLastFix() == null) {
        return super.draw(canvas, mapView, shadow, when);
      }

      if (markerDrawable != null) {
          GeoPoint lastFixGeoPoint = new GeoPoint((int)(getLastFix().getLatitude() * 1E6), (int)(getLastFix().getLongitude() * 1E6));
          mapView.getProjection().toPixels(lastFixGeoPoint, currentPoint);

          drawAt(canvas, markerDrawable, currentPoint.x, currentPoint.y, shadow);
    } else if (getMyLocation() != null) {
        drawMyLocation(canvas, mapView, getLastFix(), getMyLocation(), when);
    }
      return super.draw(canvas, mapView, shadow, when);
}

What am I missing? Thanks in advance.

Finally, I could draw a shadow to a custom marker for MyLocationOverlay, with the following:

@Override
protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
    mapView.getProjection().toPixels(myLocation, currentPoint);

    canvas.drawBitmap(shadowBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null);
    canvas.drawBitmap(markerBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null);
}

I hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM