parent
ae2dee36e3
commit
f7a94e1700
@ -1,6 +1,77 @@
|
|||||||
package fr.iut.mapping
|
package fr.iut.mapping
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.provider.Settings.Global.getString
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.mapbox.mapboxsdk.Mapbox
|
||||||
|
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapView
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapboxMapOptions
|
||||||
|
import com.mapbox.mapboxsdk.maps.Style
|
||||||
|
|
||||||
class FirstFragment:Fragment(R.layout.fragment_map_page) {
|
class FirstFragment:Fragment(R.layout.fragment_map_page) {
|
||||||
|
private var mapView: MapView? = null
|
||||||
|
|
||||||
|
// Returns the Jawg url depending on the style given (jawg-streets by default)
|
||||||
|
// See /res/values/strings which contains the url, the list of styles and your access token.
|
||||||
|
private fun makeStyleUrl(): String {
|
||||||
|
print("${getString(R.string.mapbox_style_url)}")
|
||||||
|
return "${getString(R.string.mapbox_style_url)}";
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
Mapbox.getInstance(requireContext())
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
val rootView = inflater.inflate(R.layout.fragment_map_page, container, false)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// We get the map view to set its style with the desired Jawg url.
|
||||||
|
mapView = rootView.findViewById(R.id.mapView)
|
||||||
|
mapView?.onCreate(savedInstanceState)
|
||||||
|
mapView?.getMapAsync { map ->
|
||||||
|
map.setStyle(makeStyleUrl()) {
|
||||||
|
// Map fully loaded in this scope.
|
||||||
|
// Update attributions position
|
||||||
|
map.uiSettings.setAttributionMargins(15, 0, 0, 15)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootView
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
mapView?.onStart()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
mapView?.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
mapView?.onPause()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
mapView?.onStop()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLowMemory() {
|
||||||
|
super.onLowMemory()
|
||||||
|
mapView?.onLowMemory()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
mapView?.onDestroy()
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,14 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
tools:context=".MapPage">
|
|
||||||
|
|
||||||
<!-- TODO: Update blank fragment layout -->
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:text="@string/mapPage" />
|
|
||||||
|
|
||||||
|
<com.mapbox.mapboxsdk.maps.MapView
|
||||||
|
android:id="@+id/mapView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
Loading…
Reference in new issue