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 bdb332539c9bd202e3f81a4d4613fb9310bfb4c3..c5ad88440ada803377083dcea581ef9c05082192 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, dpi) + withProperties(PropertyFactory.linePattern(name)) + styleBuilder.withImage(name, it.makeBitmap(circle.strokeColor, circle.strokeWidth, dpi)) + } + }).withSource(GeoJsonSource("${circle.id}s", circle.line.annotationOptions.geometry)) } // Add markers 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 9cfd084a7173c26c5f5f5bf14156a6096de06bd6..0214f9ca5d935f1b84a78e0e63e817bf0244ac07 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 6f8e3f7ab60c6112751ad2d1bdeb5843e2e5e12c..1278df94d9b5c0e29a50a16ad43f24978f8f0b4b 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() { }