Draw a GeoJSON line
Load a polyline to a style using GeoJsonSource and display it on a map using LineLayer.
package com.mapbox.maps.testapp.examples.linesandpolygons import android.os.Bundleimport androidx.appcompat.app.AppCompatActivityimport com.mapbox.geojson.Pointimport com.mapbox.maps.CameraOptionsimport com.mapbox.maps.MapViewimport com.mapbox.maps.Styleimport com.mapbox.maps.extension.style.layers.generated.lineLayerimport com.mapbox.maps.extension.style.layers.properties.generated.LineCapimport com.mapbox.maps.extension.style.layers.properties.generated.LineJoinimport com.mapbox.maps.extension.style.sources.generated.geoJsonSourceimport com.mapbox.maps.extension.style.style /*** Load a polyline to a style using GeoJsonSource and display it on a map using LineLayer.*/class DrawGeoJsonLineActivity : AppCompatActivity() { public override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)val mapView = MapView(this)setContentView(mapView)mapView.mapboxMap.setCamera(CameraOptions.Builder().center(Point.fromLngLat(LATITUDE,LONGITUDE)).zoom(ZOOM).build())mapView.mapboxMap.loadStyle((style(style = Style.STANDARD) {+geoJsonSource(GEOJSON_SOURCE_ID) {url("asset://from_crema_to_council_crest.geojson")}+lineLayer("linelayer", GEOJSON_SOURCE_ID) {lineCap(LineCap.ROUND)lineJoin(LineJoin.ROUND)lineOpacity(0.7)lineWidth(8.0)lineColor("#888")}}))} companion object {private const val GEOJSON_SOURCE_ID = "line"private const val LATITUDE = -122.486052private const val LONGITUDE = 37.830348private const val ZOOM = 14.0}}
Was this example helpful?