現在地アイコンを変更する方法
private fun initLocationComponent() {
val locationComponentPlugin = binding.mapView.location
locationComponentPlugin.updateSettings {
this.enabled = true
this.locationPuck = LocationPuck2D(
bearingImage = AppCompatResources.getDrawable(this@MainActivity,
R.drawable.ic_baseline_navigation_24
),
shadowImage = AppCompatResources.getDrawable(this@MainActivity,
R.drawable.mapbox_user_icon_shadow
),
scaleExpression = interpolate {
linear()
zoom()
stop {
literal(0.0)
literal(0.6)
}
stop {
literal(20.0)
literal(1.0)
}
}.toJson()
)
}
}

軌跡を動的に描画する方法
まず、 loadStyle()
時に軌跡描画用の lineLayer
および geoJsonSource
を追加しておく
binding.mapView.getMapboxMap().loadStyle(
styleExtension = style("...") {
...
+geoJsonSource(id = SOURCE_ID_MY_ROUTE)
+lineLayer(layerId = LAYER_ID_MY_ROUTE, sourceId = SOURCE_ID_MY_ROUTE) {
lineCap(LineCap.ROUND)
lineJoin(LineJoin.ROUND)
lineWidth(6.0)
lineColor("#2E98EA")
}
}
)
その後、軌跡データを取得したら、先ほど追加した geoJsonSource
を取り出し、軌跡データを詰め込んだ Feature
を作成しセットする
fun drawRoute() {
val style = binding.mapView.getMapboxMap().getStyle() ?: return
val source = style.getSourceAs(SOURCE_ID_MY_ROUTE) as GeoJsonSource? ?: return
source.feature(Feature.fromGeometry(LineString.fromLngLats(points)))
}

参考