From 824e713c51c5aa5b89a85ed5e4c105f5e76a4ba8 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Wed, 15 Dec 2021 13:57:43 +0300 Subject: [PATCH] Add mapview to the layout. --- build.gradle | 2 ++ vector/build.gradle | 3 +++ .../location/LocationSharingFragment.kt | 19 +++++++++++++++++++ .../res/layout/fragment_location_sharing.xml | 5 +++++ 4 files changed, 29 insertions(+) diff --git a/build.gradle b/build.gradle index e17f357905..29c3e61a44 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,8 @@ allprojects { groups.jitsi.group.each { includeGroup it } } } + // TODO. MapTiler + mavenCentral() google { content { groups.google.regex.each { includeGroupByRegex it } diff --git a/vector/build.gradle b/vector/build.gradle index a578fdb52f..c3dd6ba50c 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -486,6 +486,9 @@ dependencies { } implementation 'commons-codec:commons-codec:1.15' + // MapTiler + implementation 'org.maplibre.gl:android-sdk:9.5.2' + // TESTS testImplementation libs.tests.junit diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt index fd2e48546d..7c59972871 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt @@ -21,6 +21,8 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.airbnb.mvrx.activityViewModel +import com.mapbox.mapboxsdk.Mapbox +import im.vector.app.BuildConfig import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.databinding.FragmentLocationSharingBinding import javax.inject.Inject @@ -34,7 +36,24 @@ class LocationSharingFragment @Inject constructor() : return FragmentLocationSharingBinding.inflate(inflater, container, false) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + // Initialize Mapbox before inflating mapView + Mapbox.getInstance(requireContext()) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + + initMapView(savedInstanceState) + } + + private fun initMapView(savedInstanceState: Bundle?) { + val key = BuildConfig.mapTilerKey + val styleUrl = "https://api.maptiler.com/maps/streets/style.json?key=${key}" + views.mapView.onCreate(savedInstanceState) + views.mapView.getMapAsync { map -> + map.setStyle(styleUrl) + } } } diff --git a/vector/src/main/res/layout/fragment_location_sharing.xml b/vector/src/main/res/layout/fragment_location_sharing.xml index 77d9ef65f8..6399b41796 100644 --- a/vector/src/main/res/layout/fragment_location_sharing.xml +++ b/vector/src/main/res/layout/fragment_location_sharing.xml @@ -3,4 +3,9 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + \ No newline at end of file