1

I am using Mapbox SDK for Android (Mapbox SDK version 9.x.x), and I am trying to use two vector tilesets at the same time. Idea was to add each vector tileset as a separate layer, similarly as it can be done with raster tilesets, but it looks impossible. Why?

Well:

val firstStyle = "https://path/to/first.json"
val secondStyle = "https://path/to/second.json"
mapboxMap.setStyle(Style.Builder().fromUri(firstStyle)) { style: Style ->

    val secondVectorSource = VectorSource("second", secondStyle)
    style.addSource(secondVectorSource)

    // #second
    val lineLayer = LineLayer("second", "second")
    lineLayer.setSourceLayer("internal-layer-from-second-style")
    lineLayer.setProperties(
        lineJoin(Property.LINE_JOIN_ROUND),
        lineCap(Property.LINE_CAP_ROUND),
        lineColor(Color.parseColor("#ff0000")),
        lineWidth(1.5f)
    )
    style.addLayer(lineLayer)
}

You see, vector styles have internal layers with different features, and loading and showing all of them seems possible only with firstStyle, when you pass it to Style.Builder. That way all of the internal layers of firstStyle become layers of the Style.

And that's it, once I build style using Builder I see no other way to add another vector tileset with all layers just like that.

What I can do is to create new VectorSource with secondStyle, but manually pick the layers from it (part I marked in my example as #second) and add it. And I need to be aware what kind of vector layer is it (in my example it was LineLayer)

I don't know how to generically just add both firstStyle and secondStyle tilesets, without messing with particular layers. I tried invoking twice Style.Builder() to make two styles manually, and merge them somehow, but .build() method is private inside SDK :)

Anyone has any idea?

Thanks

SadClown
  • 648
  • 8
  • 16

0 Answers0