https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
d

Dzmitry Petrushenka

08/01/2022, 4:24 PM
Hi Guys! I was wondering if anyone here has advanced experience with Mapbox Android SDK. Just in case - my quesion is about implementing similar piechart thing in Android using Mapbox SDK like Mabox GL JS does here https://docs.mapbox.com/mapbox-gl-js/example/cluster-html/
m

mkrussel

08/01/2022, 7:51 PM
I've not actually played with clustering, but the logic should mostly be identical. Instead of creating JSON objects for the different properties and expressions, you need to use the DSL they generate. So the clusterProperties would be
Copy code
val mag1 = lt {
        get("mag")
        literal(2)
    }
    val mag2 = all {
        gte {
            get("mag")
            literal(2)
        }
        lt {
            get("mag")
            literal(3)
        }
    }
    val mag3 = all {
        gte {
            get("mag")
            literal(3)
        }
        lt {
            get("mag")
            literal(4)
        }
    }
    val mag4 = gte {
        get("mag")
        literal(4)
    }
    val earthQuakes = geoJsonSource("earthquakes") {
        data("<https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson>")
        cluster(true)
        clusterRadius(80)
        clusterProperty(
            "mag1",
            sum {
                Expression.switchCase(mag1, Expression.literal(1), Expression.literal(0))
            }
        )
        clusterProperty(
            "mag2",
            sum {
                Expression.switchCase(mag2, Expression.literal(1), Expression.literal(0))
            }
        )
        clusterProperty(
            "mag3",
            sum {
                Expression.switchCase(mag3, Expression.literal(1), Expression.literal(0))
            }
        )
        clusterProperty(
            "mag4",
            sum {
                Expression.switchCase(mag4, Expression.literal(1), Expression.literal(0))
            }
        )
    }
Then there is the same type of translate for all the other layer properties
All the
["something", ...]
code are expressions. So the trick is to make the first string to the expression function in the DSL.
And all the object properties int he object literals should map to functions for that object type in the DSL.
Never mind most of what I posted. I thought the circle-color was doing something fancier than I thought it could do. They are basically creating a view and creating a marker that displays it. The android equivalent would be https://docs.mapbox.com/android/maps/guides/annotations/view-annotations/
I also had problems with view annotations in previous versions of Mapbox on Android because the map renders on a different thread then the UI so there would be some different while panning around.
d

Dzmitry Petrushenka

08/02/2022, 7:05 AM
thank you @mkrussel! I was mainly wondering how to draw PieChart in Adnroid similar to HTML dynamic Svg building - maybe will try to go with prebuilt images for different Pie states
24 Views