Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RotableMarker extends Marker {
- private Boolean isBearingAvailable = Boolean.FALSE;
- private float bearing;
- public RotableMarker(LatLong latLong, Bitmap bitmap, int horizontalOffset, int verticalOffset, float b) {
- super(latLong, bitmap, horizontalOffset, verticalOffset);
- isBearingAvailable = Boolean.TRUE;
- bearing = b;
- }
- @Override
- public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
- if (this.getLatLong() == null || this.getBitmap() == null || this.getBitmap().isDestroyed()) {
- return;
- }
- long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
- double pixelX = MercatorProjection.longitudeToPixelX(this.getLatLong().longitude, mapSize);
- double pixelY = MercatorProjection.latitudeToPixelY(this.getLatLong().latitude, mapSize);
- int halfBitmapWidth = this.getBitmap().getWidth() / 2;
- int halfBitmapHeight = this.getBitmap().getHeight() / 2;
- int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.getHorizontalOffset());
- int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.getVerticalOffset());
- int right = left + this.getBitmap().getWidth();
- int bottom = top + this.getBitmap().getHeight();
- Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom);
- Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
- if(canvasRectangle.intersects(bitmapRectangle)) {
- // Rotate the marker based on bearing for example (or whatever angle you want)
- android.graphics.Canvas androidCanvas = AndroidGraphicFactory.getCanvas(canvas);
- androidCanvas.save();
- float px = (right + left) / 2f;
- float py = (bottom + top) / 2f;
- androidCanvas.rotate(bearing, px, py);
- canvas.drawBitmap(this.getBitmap(), left, top);
- androidCanvas.restore();
- } else {
- canvas.drawBitmap(this.getBitmap(), left, top);
- }
- }
- }
Add Comment
Please, Sign In to add comment