|
|
@ -9,6 +9,7 @@ import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
|
|
|
|
import android.widget.Toast
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
@ -21,13 +22,14 @@ import com.mapbox.mapboxsdk.plugins.annotation.Symbol
|
|
|
|
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
|
|
|
|
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
|
|
|
|
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions
|
|
|
|
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions
|
|
|
|
import com.mapbox.mapboxsdk.utils.BitmapUtils
|
|
|
|
import com.mapbox.mapboxsdk.utils.BitmapUtils
|
|
|
|
|
|
|
|
import fr.iut.mapping.API.RestaurantData
|
|
|
|
import fr.iut.mapping.API.getRestaurants
|
|
|
|
import fr.iut.mapping.API.getRestaurants
|
|
|
|
import kotlinx.android.synthetic.main.fragment_map_page.*
|
|
|
|
import kotlinx.android.synthetic.main.fragment_map_page.*
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//https://maplibre.org/maplibre-gl-native/android/api/index.html
|
|
|
|
//https://maplibre.org/maplibre-gl-native/android/api/index.html
|
|
|
|
class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
|
|
|
|
class FirstFragment: Fragment(R.layout.fragment_map_page) {
|
|
|
|
companion object {
|
|
|
|
companion object {
|
|
|
|
private const val MARKER_SELECTED_ICON = "JAWG_ICON"
|
|
|
|
private const val MARKER_SELECTED_ICON = "JAWG_ICON"
|
|
|
|
private const val MARKER_ICON = "MARKER_ICON"
|
|
|
|
private const val MARKER_ICON = "MARKER_ICON"
|
|
|
@ -37,6 +39,9 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
|
|
|
|
private var symbolManager: SymbolManager? = null
|
|
|
|
private var symbolManager: SymbolManager? = null
|
|
|
|
private var lastSymbol: Symbol? = null
|
|
|
|
private var lastSymbol: Symbol? = null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var locationListener: fr.iut.mapping.LocationListener
|
|
|
|
|
|
|
|
private lateinit var listRestaurant: List<RestaurantData>
|
|
|
|
|
|
|
|
|
|
|
|
private fun makeStyleUrl(): String {
|
|
|
|
private fun makeStyleUrl(): String {
|
|
|
|
return "${getString(R.string.mapbox_style_url)}";
|
|
|
|
return "${getString(R.string.mapbox_style_url)}";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -45,14 +50,40 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
|
|
|
|
|
|
val list = getRestaurants(51.5,-0.11,1000)
|
|
|
|
locationListener = LocationListener(requireContext())
|
|
|
|
|
|
|
|
locationListener.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mapbox.getInstance(requireContext(), R.string.mapbox_access_token.toString())
|
|
|
|
Mapbox.getInstance(requireContext(), R.string.mapbox_access_token.toString())
|
|
|
|
val rootView = inflater.inflate(R.layout.fragment_map_page, container, false)
|
|
|
|
val rootView = inflater.inflate(R.layout.fragment_map_page, container, false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val button: View = rootView.findViewById(R.id.findRestaurant)
|
|
|
|
|
|
|
|
button.setOnClickListener { view ->
|
|
|
|
|
|
|
|
findAndPutRestaurant()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapView = rootView.findViewById(R.id.mapView)
|
|
|
|
mapView = rootView.findViewById(R.id.mapView)
|
|
|
|
mapView?.onCreate(savedInstanceState)
|
|
|
|
mapView?.onCreate(savedInstanceState)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapView?.getMapAsync { map ->
|
|
|
|
|
|
|
|
map.setStyle(makeStyleUrl()) { style ->
|
|
|
|
|
|
|
|
map.uiSettings.setAttributionMargins(15, 0, 0, 15)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rootView
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun findAndPutRestaurant(){
|
|
|
|
|
|
|
|
Log.e("Debug","${locationListener.latitude},${locationListener.latitude}")
|
|
|
|
|
|
|
|
listRestaurant = getRestaurants(locationListener.latitude,locationListener.latitude,1000000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(listRestaurant.isEmpty()){
|
|
|
|
|
|
|
|
Toast.makeText(requireContext(), "Pas de restaurants trouver", Toast.LENGTH_SHORT).show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mapView?.getMapAsync { map ->
|
|
|
|
mapView?.getMapAsync { map ->
|
|
|
|
map.setStyle(makeStyleUrl()) { style ->
|
|
|
|
map.setStyle(makeStyleUrl()) { style ->
|
|
|
|
map.uiSettings.setAttributionMargins(15, 0, 0, 15)
|
|
|
|
map.uiSettings.setAttributionMargins(15, 0, 0, 15)
|
|
|
@ -67,12 +98,11 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
|
|
|
|
this.symbolManager?.iconAllowOverlap = true
|
|
|
|
this.symbolManager?.iconAllowOverlap = true
|
|
|
|
this.symbolManager?.iconIgnorePlacement = true
|
|
|
|
this.symbolManager?.iconIgnorePlacement = true
|
|
|
|
|
|
|
|
|
|
|
|
list.forEach { restaurant ->
|
|
|
|
listRestaurant.forEach { restaurant ->
|
|
|
|
val description = "${restaurant.adress}\n${restaurant.phone ?: "Pas de numéro disponible"}\n${restaurant.lat},${restaurant.lon}"
|
|
|
|
val description = "${restaurant.adress}${restaurant.phone ?: "Pas de numéro disponible"}\n${restaurant.lat},${restaurant.lon}"
|
|
|
|
insertIconOnMap(
|
|
|
|
insertIconOnMap(
|
|
|
|
LatLng(restaurant.lat, restaurant.lon),
|
|
|
|
LatLng(restaurant.lat, restaurant.lon),
|
|
|
|
restaurant.name,
|
|
|
|
restaurant.name,
|
|
|
|
R.drawable.ic_menu_likes,
|
|
|
|
|
|
|
|
description
|
|
|
|
description
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -99,7 +129,6 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return rootView
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun toggleLayout() {
|
|
|
|
private fun toggleLayout() {
|
|
|
@ -124,7 +153,7 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
|
|
|
|
this.lastSymbol = symbol
|
|
|
|
this.lastSymbol = symbol
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun insertIconOnMap(point: LatLng, title: String, imageId: Int, description: String) {
|
|
|
|
private fun insertIconOnMap(point: LatLng, title: String, description: String) {
|
|
|
|
Log.e("Debug",title)
|
|
|
|
Log.e("Debug",title)
|
|
|
|
// Convert datas of the marker into Json object.
|
|
|
|
// Convert datas of the marker into Json object.
|
|
|
|
val jsonData = """
|
|
|
|
val jsonData = """
|
|
|
@ -169,11 +198,8 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
|
|
|
|
override fun onDestroy() {
|
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
|
|
|
super.onDestroy()
|
|
|
|
mapView?.onDestroy()
|
|
|
|
mapView?.onDestroy()
|
|
|
|
|
|
|
|
locationListener.stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//methode pour le GPS
|
|
|
|
|
|
|
|
override fun onLocationChanged(location: Location) {
|
|
|
|
|
|
|
|
print("Latitude: " + location.latitude + " , Longitude: " + location.longitude)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|