2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Mapbox Maps SDK for Android v10 実装メモ ①

Last updated at Posted at 2022-04-06

現在地アイコンを変更する方法

    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)))
}

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?