I am working on an android app. Mapbox Android SDK V: 10.8.0.
I am trying to apply Raster layer using the following function, but I am unable to get succeed. I am not even getting any error or crash, so It will indicate that I am wrong.
Can you guys help me ? My layers are not getting applied.
My code is below
fun addLayer(context: Context, mapBoxMap: MapboxMap, mapType: String, isTomorrowApi: Boolean, key: String, mapLink: String, opacity: Float) {
val url = listOf<String>(https://example.com/%7Bz%7D/%7Bx%7D/%7By%7D/fireIndex/now.png%22)
val layerId = key-layer
val sourceId = key-source
mapBoxMap.loadStyle((style(styleUri = mapType) {
val rasterSource = rasterSource(layerId){
tiles(url)
tileSize(512)
color(Color.RED)
}
val rasterLayer = rasterLayer(layerId, sourceId){
this.minZoom(0.0)
this.maxZoom(22.0)
this.rasterOpacity(opacity.toDouble())
this.sourceLayer(sourceId)
this.visibility(RasterLayer.defaultVisibility!!)
}
mapBoxMap.getStyle {
it.addSource(rasterSource)
if(it.styleLayerExists(layerId)){
it.moveStyleLayer(layerId, LayerPosition(layerId, "puck", 0))
} else {
it.addPersistentLayer(rasterLayer)
}
}
}), Style.OnStyleLoaded {
}, object : OnMapLoadErrorListener {
override fun onMapLoadError(eventData: MapLoadingErrorEventData) {
Log.d("TAG", "MapBox: error listener ${eventData.message}")
}
})
}
Expected result Example Traffic RasterLayer should look like this