From e895d25a2c5659e1d54255f31d9a56d4f63b782d Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Mon, 13 Mar 2023 21:57:07 +0100 Subject: [PATCH 1/2] Circle stroke outline in lite mode --- .../kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt index bdb332539..4b9dde3b6 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt @@ -286,8 +286,14 @@ class LiteGoogleMapImpl(context: Context, var options: GoogleMapOptions) : Abstr styleBuilder.withLayer(LineLayer("l${circle.id}s", "${circle.id}s").withProperties( PropertyFactory.lineWidth(circle.strokeWidth), PropertyFactory.lineColor(circle.strokeColor), - PropertyFactory.lineCap(Property.LINE_CAP_ROUND) - )).withSource(GeoJsonSource("${circle.id}s", circle.line.annotationOptions.geometry)) + PropertyFactory.lineCap(Property.LINE_CAP_ROUND), + ).apply { + circle.strokePattern?.let { + val name = it.getName(circle.strokeColor, circle.strokeWidth) + withProperties(PropertyFactory.linePattern(name)) + styleBuilder.withImage(name, it.makeBitmap(circle.strokeColor, circle.strokeWidth)) + } + }).withSource(GeoJsonSource("${circle.id}s", circle.line.annotationOptions.geometry)) } // Add markers -- GitLab From f18100c14e80a3b973a85afc27da2785fb7464ef Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Tue, 14 Mar 2023 12:26:43 +0100 Subject: [PATCH 2/2] Unskew circle stroke pattern in lite mode Increase dot width by dpi factor. Also increase bitmap height by dpi factor. --- .../microg/gms/maps/mapbox/LiteGoogleMap.kt | 4 +-- .../org/microg/gms/maps/mapbox/Pattern.kt | 30 +++++++++---------- .../android/gms/maps/model/PatternItem.java | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt index 4b9dde3b6..c5ad88440 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/LiteGoogleMap.kt @@ -289,9 +289,9 @@ class LiteGoogleMapImpl(context: Context, var options: GoogleMapOptions) : Abstr PropertyFactory.lineCap(Property.LINE_CAP_ROUND), ).apply { circle.strokePattern?.let { - val name = it.getName(circle.strokeColor, circle.strokeWidth) + val name = it.getName(circle.strokeColor, circle.strokeWidth, dpi) withProperties(PropertyFactory.linePattern(name)) - styleBuilder.withImage(name, it.makeBitmap(circle.strokeColor, circle.strokeWidth)) + styleBuilder.withImage(name, it.makeBitmap(circle.strokeColor, circle.strokeWidth, dpi)) } }).withSource(GeoJsonSource("${circle.id}s", circle.line.annotationOptions.geometry)) } diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Pattern.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Pattern.kt index 9cfd084a7..0214f9ca5 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Pattern.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Pattern.kt @@ -18,18 +18,18 @@ fun PatternItem.getName(): String = when (this) { /** * Name of pattern, to identify it after it is added to map */ -fun List.getName(color: Int, strokeWidth: Float) = joinToString("-") { +fun List.getName(color: Int, strokeWidth: Float, skew: Float = 1f) = joinToString("-") { it.getName() -} + "-${color}-width${strokeWidth}" +} + "-${color}-width${strokeWidth}-skew${skew}" /** * Gets width that a bitmap for this pattern item would have if the pattern's bitmap * were to be drawn with respect to aspect ratio onto a canvas with height 1. */ -fun PatternItem.getWidth(strokeWidth: Float): Float = when (this) { +fun PatternItem.getWidth(strokeWidth: Float, skew: Float): Float = when (this) { is Dash -> this.length is Gap -> this.length - is Dot -> strokeWidth + is Dot -> strokeWidth * skew else -> 1f } @@ -37,19 +37,19 @@ fun PatternItem.getWidth(strokeWidth: Float): Float = when (this) { * Gets width that a bitmap for this pattern would have if it were to be drawn * with respect to aspect ratio onto a canvas with height 1. */ -fun List.getWidth(strokeWidth: Float) = map { it.getWidth(strokeWidth) }.sum() +fun List.getWidth(strokeWidth: Float, skew: Float) = map { it.getWidth(strokeWidth, skew) }.sum() -fun List.makeBitmap(color: Int, strokeWidth: Float): Bitmap = makeBitmap(Paint().apply { +fun List.makeBitmap(color: Int, strokeWidth: Float, skew: Float = 1f): Bitmap = makeBitmap(Paint().apply { setColor(color) style = Paint.Style.FILL -}, strokeWidth) +}, strokeWidth, skew) -fun List.makeBitmap(paint: Paint, strokeWidth: Float): Bitmap { +fun List.makeBitmap(paint: Paint, strokeWidth: Float, skew: Float): Bitmap { // Pattern aspect ratio is not respected by renderer - val width = getWidth(strokeWidth).toInt() - val height = strokeWidth.toInt() // avoids squished image bugs + val width = getWidth(strokeWidth, skew).toInt() + val height = (strokeWidth * skew).toInt() // avoids squished image bugs val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) @@ -60,8 +60,8 @@ fun List.makeBitmap(paint: Paint, strokeWidth: Float): Bitmap { is Dash -> canvas.drawRect( drawCursor, 0f, - drawCursor + item.length, - strokeWidth, + drawCursor + item.getWidth(strokeWidth, skew), + strokeWidth * skew, paint ) @@ -70,13 +70,13 @@ fun List.makeBitmap(paint: Paint, strokeWidth: Float): Bitmap { is Dot -> canvas.drawOval( drawCursor, 0f, - drawCursor + item.getWidth(strokeWidth), - strokeWidth, + drawCursor + item.getWidth(strokeWidth, skew), + strokeWidth * skew, paint ) } - drawCursor += item.getWidth(strokeWidth) + drawCursor += item.getWidth(strokeWidth, skew) } return bitmap diff --git a/play-services-maps/src/main/java/com/google/android/gms/maps/model/PatternItem.java b/play-services-maps/src/main/java/com/google/android/gms/maps/model/PatternItem.java index 6f8e3f7ab..1278df94d 100644 --- a/play-services-maps/src/main/java/com/google/android/gms/maps/model/PatternItem.java +++ b/play-services-maps/src/main/java/com/google/android/gms/maps/model/PatternItem.java @@ -21,7 +21,7 @@ public class PatternItem extends AutoSafeParcelable { @Field(2) private int type; @Field(3) - private float length; + private Float length; private PatternItem() { } -- GitLab