@ -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 ( ) {
map View ?. layoutParams = LinearLayout . LayoutParams ( ViewGroup . LayoutParams . MATCH _PARENT , 0 , 2f )
map Layout ?. 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 ( )