Skip to content

Commit

Permalink
cluster pins later, scale overlay icons a bit by zoom (mitigates #5835,
Browse files Browse the repository at this point in the history
fixes #5848)
  • Loading branch information
westnordost committed Aug 28, 2024
1 parent e8eff5a commit cb4f4c0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ class MainFragment :
}

private fun updateCreateButtonEnablement(zoom: Double) {
binding.createButton.isEnabled = zoom >= 18.0
binding.createButton.isEnabled = zoom >= 17.0
}

private fun setIsNavigationMode(navigation: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class GeometryMarkersMapComponent(
.withProperties(
iconColor("#D140D0"),
iconImage(get("icon")),
iconSize(interpolate(linear(), zoom(), stop(17, 0.5f), stop(19, 1f))),
iconAllowOverlap(true),
textField(get("label")),
textAnchor(Property.TEXT_ANCHOR_TOP),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import org.maplibre.android.style.expressions.Expression.division
import org.maplibre.android.style.expressions.Expression.get
import org.maplibre.android.style.expressions.Expression.gt
import org.maplibre.android.style.expressions.Expression.gte
import org.maplibre.android.style.expressions.Expression.interpolate

Check failure on line 28 in app/src/main/java/de/westnordost/streetcomplete/screens/main/map/components/PinsMapComponent.kt

View workflow job for this annotation

GitHub Actions / Kotlin

Unused import
import org.maplibre.android.style.expressions.Expression.linear
import org.maplibre.android.style.expressions.Expression.literal
import org.maplibre.android.style.expressions.Expression.log2
import org.maplibre.android.style.expressions.Expression.lte
import org.maplibre.android.style.expressions.Expression.stop
import org.maplibre.android.style.expressions.Expression.sum
import org.maplibre.android.style.expressions.Expression.toNumber
import org.maplibre.android.style.expressions.Expression.zoom
Expand Down Expand Up @@ -64,7 +67,7 @@ class PinsMapComponent(
val layers: List<Layer> = listOf(
SymbolLayer("pin-cluster-layer", SOURCE)
.withFilter(all(
gte(zoom(), 14f),
gte(zoom(), 13f),
lte(zoom(), CLUSTER_MAX_ZOOM),
gt(toNumber(get("point_count")), 1)
))
Expand All @@ -86,18 +89,23 @@ class PinsMapComponent(
.withProperties(
circleColor("white"),
circleStrokeColor("#aaaaaa"),
circleRadius(4f),
circleRadius(6f),
circleStrokeWidth(1f),
circleTranslate(arrayOf(0f, -6f)), // so that it hides behind the pin
circleTranslate(arrayOf(0f, -8f)), // so that it hides behind the pin
circleTranslateAnchor(Property.CIRCLE_TRANSLATE_ANCHOR_VIEWPORT),
),
SymbolLayer("pins-layer", SOURCE)
.withFilter(gt(zoom(), CLUSTER_MAX_ZOOM))
.withProperties(
iconImage(get("icon-image")),
// constant icon size because click area would become a bit too small and more
// importantly, dynamic size per zoom + collision doesn't work together well, it
// results in a lot of flickering.
iconSize(1f),

// better would be arrayOf(-2.5f, 0f, -7f, 2.5f) or something like that, but setting
// different paddings per side is not supported by MapLibre Native yet
// different paddings per side is not supported by MapLibre Native yet. See
// https://github.com/maplibre/maplibre-native/issues/2368
iconPadding(-2f),
iconOffset(listOf(-4.5f, -34.5f).toTypedArray()),
symbolSortKey(get("icon-order")),
Expand Down Expand Up @@ -178,7 +186,7 @@ class PinsMapComponent(

companion object {
private const val SOURCE = "pins-source"
private const val CLUSTER_MAX_ZOOM = 16
private const val CLUSTER_MAX_ZOOM = 14
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class StyleableOverlayMapComponent(
))
.withProperties(
iconImage(get("icon")),
iconSize(interpolate(linear(), zoom(), stop(17, 0.5f), stop(19, 1f))),
textField(get("label")),
textFont(arrayOf("Roboto Regular")),
textAnchor(Property.TEXT_ANCHOR_TOP),
Expand Down

0 comments on commit cb4f4c0

Please sign in to comment.