add pop up info

master
Bastien OLLIER 2 years ago
parent 0a2327dda6
commit f555769438

@ -3,6 +3,7 @@ package fr.iut.mapping
import android.Manifest.permission.ACCESS_COARSE_LOCATION import android.Manifest.permission.ACCESS_COARSE_LOCATION
import android.Manifest.permission.ACCESS_FINE_LOCATION import android.Manifest.permission.ACCESS_FINE_LOCATION
import android.location.Location
import android.os.Build import android.os.Build
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle

@ -8,7 +8,6 @@ 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
@ -35,8 +34,6 @@ 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 val locationPermissionCode = 2
private fun makeStyleUrl(): String { private fun makeStyleUrl(): String {
return "${getString(R.string.mapbox_style_url)}"; return "${getString(R.string.mapbox_style_url)}";
} }
@ -54,6 +51,7 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
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)
// Add an icons ("classic" and "selected") to the map style.
val selectedMarkerIconDrawable = ResourcesCompat.getDrawable(this.resources, R.drawable.ic_menu_likes, null) val selectedMarkerIconDrawable = ResourcesCompat.getDrawable(this.resources, R.drawable.ic_menu_likes, null)
style.addImage(MARKER_ICON, BitmapUtils.getBitmapFromDrawable(selectedMarkerIconDrawable)!!) style.addImage(MARKER_ICON, BitmapUtils.getBitmapFromDrawable(selectedMarkerIconDrawable)!!)
val markerIconDrawable = ResourcesCompat.getDrawable(this.resources, R.drawable.ic_menu_likes, null) val markerIconDrawable = ResourcesCompat.getDrawable(this.resources, R.drawable.ic_menu_likes, null)
@ -64,20 +62,16 @@ 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
// Insert markers with their associated data.
insertIconOnMap( insertIconOnMap(
LatLng(51.50853, -0.076132), LatLng(51.50853, -0.076132),
"Tower of London", "Tower of London",
R.drawable.ic_menu_likes, R.drawable.ic_menu_likes,
"It is a historic castle on the north bank of the River Thames in central London." + "It is a historic castle on the north bank of the River Thames in central London."
"It lies within the London Borough of Tower Hamlets, which is separated from the eastern edge of the square mile of the City of London by the open space known as Tower Hill." +
"It was founded towards the end of 1066 as part of the Norman Conquest of England."
) )
// Add a listener to trigger markers clicks. // Add a listener to trigger markers clicks.
this.symbolManager?.addClickListener { this.symbolManager?.addClickListener {
// Put all marker information into the layout. // Put all marker information into the layout.
titleView.text = it.data?.asJsonObject?.get("title")?.asString titleView.text = it.data?.asJsonObject?.get("title")?.asString
descriptionView.text = it.data?.asJsonObject?.get("description")?.asString descriptionView.text = it.data?.asJsonObject?.get("description")?.asString
descriptionLayout.background = ContextCompat.getDrawable(requireContext(),it.data?.asJsonObject?.get("imageId")?.asInt!!) descriptionLayout.background = ContextCompat.getDrawable(requireContext(),it.data?.asJsonObject?.get("imageId")?.asInt!!)
@ -87,6 +81,7 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
toggleLayout() toggleLayout()
true true
} }
} }
} }
@ -94,7 +89,7 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
} }
private fun toggleLayout() { private fun toggleLayout() {
mapView?.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 2f) mapLayout?.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 2f)
descriptionLayout?.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f) descriptionLayout?.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
} }
@ -126,13 +121,12 @@ class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
""" """
// Add symbol at specified lat/lon. // Add symbol at specified lat/lon.
val newSymbol = symbolManager!!.create( val newSymbol = symbolManager!!.create(
SymbolOptions() SymbolOptions().withLatLng(LatLng(point.latitude, point.longitude)).withData(JsonParser.parseString(jsonData))
.withLatLng(LatLng(point.latitude, point.longitude))
.withData(JsonParser.parseString(jsonData))
) )
setDefaultIcon(newSymbol) setDefaultIcon(newSymbol)
} }
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
mapView?.onStart() mapView?.onStart()

Loading…
Cancel
Save