Skip to content

Commit 9295b69

Browse files
Fix small border of zoom out marker, add shadow
1 parent e3ce41d commit 9295b69

File tree

1 file changed

+19
-10
lines changed
  • lib-compose/src/main/java/com/what3words/components/compose/maps/utils

1 file changed

+19
-10
lines changed

lib-compose/src/main/java/com/what3words/components/compose/maps/utils/BitmapUtils.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,27 @@ fun getPinBitmap(
7575

7676
return getBitMapFromPathData(
7777
listOf(
78-
DrawPath(context.getString(R.string.path_pin_circle),
79-
Paint().apply {
80-
style = Paint.Style.STROKE
81-
strokeWidth = 2f * density
82-
isAntiAlias = true
83-
color = android.graphics.Color.WHITE
84-
}
85-
),
8678
DrawPath(context.getString(R.string.path_pin_circle),
8779
Paint().apply {
8880
color = colorMarker.background.toArgb()
81+
// Draw shadow with radius 3dp (+2dp) of the stroke
82+
// The design has 2 shadow layers
83+
setShadowLayer(5 * density, 0f, 0f, Color(0x26000000).toArgb())
84+
setShadowLayer(4 * density, 0f, 0f, Color(0x4D000000).toArgb())
8985
}
9086
),
9187
DrawPath(context.getString(R.string.path_pin_slashes),
9288
Paint().apply {
9389
color = colorMarker.slash.toArgb()
9490
}
91+
),
92+
DrawPath(context.getString(R.string.path_pin_circle),
93+
Paint().apply {
94+
style = Paint.Style.STROKE
95+
strokeWidth = 2f * density
96+
isAntiAlias = true
97+
color = android.graphics.Color.WHITE
98+
}
9599
)
96100
),
97101
pinSize,
@@ -109,15 +113,17 @@ fun getBitMapFromPathData(
109113
listDrawPath: List<DrawPath>,
110114
width: Int,
111115
height: Int,
112-
scaleFactor: Float
116+
scaleFactor: Float,
117+
padding: Int = 4, // Default padding for shadow in dp
113118
): Bitmap {
114119
// Calculate scaled dimensions
115120
val widthScaled = (width * scaleFactor).toInt()
116121
val heightScaled = (height * scaleFactor).toInt()
122+
val paddingPx = (padding * scaleFactor).toInt()
117123

118124
// Create a Bitmap of the target size
119125
val bitmap = try {
120-
Bitmap.createBitmap(widthScaled, heightScaled, Bitmap.Config.ARGB_8888)
126+
Bitmap.createBitmap(widthScaled + paddingPx * 2, heightScaled + paddingPx * 2, Bitmap.Config.ARGB_8888)
121127
} catch (e: OutOfMemoryError) {
122128
throw IllegalArgumentException("Bitmap too large to allocate", e)
123129
}
@@ -128,6 +134,9 @@ fun getBitMapFromPathData(
128134
// Create and apply scaling transformation
129135
val matrix = Matrix().apply { setScale(scaleFactor, scaleFactor) }
130136

137+
// Translate canvas to account for padding
138+
canvas.translate(paddingPx.toFloat(), paddingPx.toFloat())
139+
131140
// Draw each path onto the canvas
132141
listDrawPath.forEach { drawPath ->
133142
try {

0 commit comments

Comments
 (0)