Guest User

Untitled

a guest
Oct 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. public class RotableMarker extends Marker {
  2.  
  3. private Boolean isBearingAvailable = Boolean.FALSE;
  4. private float bearing;
  5.  
  6. public RotableMarker(LatLong latLong, Bitmap bitmap, int horizontalOffset, int verticalOffset, float b) {
  7. super(latLong, bitmap, horizontalOffset, verticalOffset);
  8.  
  9. isBearingAvailable = Boolean.TRUE;
  10. bearing = b;
  11. }
  12.  
  13. @Override
  14. public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
  15. if (this.getLatLong() == null || this.getBitmap() == null || this.getBitmap().isDestroyed()) {
  16. return;
  17. }
  18.  
  19. long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
  20. double pixelX = MercatorProjection.longitudeToPixelX(this.getLatLong().longitude, mapSize);
  21. double pixelY = MercatorProjection.latitudeToPixelY(this.getLatLong().latitude, mapSize);
  22.  
  23. int halfBitmapWidth = this.getBitmap().getWidth() / 2;
  24. int halfBitmapHeight = this.getBitmap().getHeight() / 2;
  25.  
  26. int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.getHorizontalOffset());
  27. int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.getVerticalOffset());
  28. int right = left + this.getBitmap().getWidth();
  29. int bottom = top + this.getBitmap().getHeight();
  30.  
  31. Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom);
  32. Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
  33. if(canvasRectangle.intersects(bitmapRectangle)) {
  34. // Rotate the marker based on bearing for example (or whatever angle you want)
  35. android.graphics.Canvas androidCanvas = AndroidGraphicFactory.getCanvas(canvas);
  36. androidCanvas.save();
  37. float px = (right + left) / 2f;
  38. float py = (bottom + top) / 2f;
  39. androidCanvas.rotate(bearing, px, py);
  40. canvas.drawBitmap(this.getBitmap(), left, top);
  41. androidCanvas.restore();
  42. } else {
  43. canvas.drawBitmap(this.getBitmap(), left, top);
  44. }
  45. }
  46. }
Add Comment
Please, Sign In to add comment