use of org.mapsforge.core.model.Rectangle in project RSAndroidApp by RailwayStations.
the class ClusterMarker method draw.
@Override
public synchronized void draw(final BoundingBox boundingBox, final byte zoomLevel, final org.mapsforge.core.graphics.Canvas canvas, final Point topLeftPoint) {
if (cluster.getClusterManager() == null || this.getLatLong() == null) {
return;
}
setMarkerBitmap();
final long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
final double pixelX = MercatorProjection.longitudeToPixelX(this.getLatLong().longitude, mapSize);
final double pixelY = MercatorProjection.latitudeToPixelY(this.getLatLong().latitude, mapSize);
final double halfBitmapWidth;
final double halfBitmapHeight;
final var markerBitmap = cluster.getClusterManager().markerIconBmps.get(markerType);
final var bitmap = markerBitmap.getBitmap(hasPhoto(), ownPhoto(), stationActive(), isPendingUpload());
try {
halfBitmapWidth = bitmap.getWidth() / 2f;
halfBitmapHeight = bitmap.getHeight() / 2f;
} catch (final NullPointerException e) {
Log.e(ClusterMarker.TAG, e.getMessage(), e);
return;
}
final int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + markerBitmap.getIconOffset().x);
final int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + markerBitmap.getIconOffset().y);
final int right = (left + bitmap.getWidth());
final int bottom = (top + bitmap.getHeight());
final var bitmapRectangle = new Rectangle(left, top, right, bottom);
final var canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
if (!canvasRectangle.intersects(bitmapRectangle)) {
return;
}
// Draw bitmap
canvas.drawBitmap(bitmap, left, top);
// Draw Text
if (markerType == 0) {
// Draw bitmap
final var bubble = MarkerBitmap.getBitmapFromTitle(cluster.getTitle(), markerBitmap.getPaint());
canvas.drawBitmap(bubble, (int) (left + halfBitmapWidth - bubble.getWidth() / 2), (top - bubble.getHeight()));
} else {
final int x = (int) (left + bitmap.getWidth() * 1.3);
final int y = (int) (top + bitmap.getHeight() * 1.3 + markerBitmap.getPaint().getTextHeight(cluster.getTitle()) / 2);
canvas.drawText(cluster.getTitle(), x, y, markerBitmap.getPaint());
}
}