aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
diff options
context:
space:
mode:
authorIsidro Henoch <imhenoch@protonmail.com>2022-01-04 01:49:21 -0600
committerIsidro Henoch <imhenoch@protonmail.com>2022-01-04 01:49:21 -0600
commit3d93d742c9dc05ff103a16739c08315ebb680a15 (patch)
tree108ad1273b335eeee02280f59df6b266e87ff6ce /androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
parent6168604aa62be4bc547a6d0e1a26ef786d748c77 (diff)
downloadetbsa-trackermap-mobile-3d93d742c9dc05ff103a16739c08315ebb680a15.tar.gz
etbsa-trackermap-mobile-3d93d742c9dc05ff103a16739c08315ebb680a15.tar.bz2
etbsa-trackermap-mobile-3d93d742c9dc05ff103a16739c08315ebb680a15.zip
Finishes the markers functionality
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt33
1 files changed, 33 insertions, 0 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
index bd17013..106a2d9 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
@@ -8,7 +8,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.mousebird.maply.ComponentObject
+import com.mousebird.maply.GlobeController
import com.mousebird.maply.GlobeMapFragment
+import com.mousebird.maply.MapController
import com.mousebird.maply.MarkerInfo
import com.mousebird.maply.Point2d
import com.mousebird.maply.QuadImageLoader
@@ -17,11 +19,14 @@ import com.mousebird.maply.RenderController
import com.mousebird.maply.RenderControllerInterface
import com.mousebird.maply.SamplingParams
import com.mousebird.maply.ScreenMarker
+import com.mousebird.maply.SelectedObject
import com.mousebird.maply.SphericalMercatorCoordSystem
import java.io.File
import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.R
+typealias MarkerCallback = (Int?) -> Unit
+
@DelicateCoroutinesApi
class MapFragment : GlobeMapFragment() {
@@ -37,6 +42,8 @@ class MapFragment : GlobeMapFragment() {
val type: MarkerType = MarkerType.DEFAULT
)
+ var markerCallback: MarkerCallback? = null
+
private val markers = mutableListOf<Pair<ScreenMarker, ComponentObject>>()
override fun chooseDisplayType(): MapDisplayType {
@@ -81,6 +88,31 @@ class MapFragment : GlobeMapFragment() {
mapControl.setPositionGeo(longitude, latitude, zoom)
}
+ override fun userDidSelect(
+ mapControl: MapController?,
+ selObjs: Array<out SelectedObject>?,
+ loc: Point2d?,
+ screenLoc: Point2d?
+ ) {
+ super.userDidSelect(mapControl, selObjs, loc, screenLoc)
+
+ selObjs?.forEach { selectedObject ->
+ if (selectedObject.selObj is ScreenMarker) {
+ val screenMarker = selectedObject.selObj as ScreenMarker
+ val markerId = screenMarker.userObject as Int
+ Log.d("MapFragment", "Selected marker with id: $markerId")
+
+ markerCallback?.let { it(markerId) }
+ }
+ }
+ }
+
+ override fun userDidTap(mapControl: MapController?, loc: Point2d?, screenLoc: Point2d?) {
+ super.userDidTap(mapControl, loc, screenLoc)
+
+ markerCallback?.let { it(null) }
+ }
+
fun clear() {
mapControl.removeObjects(
markers.map { it.second },
@@ -101,6 +133,7 @@ class MapFragment : GlobeMapFragment() {
screenMarker.image = getIcon(marker.type)
screenMarker.size = markerSize
screenMarker.userObject = marker.id
+ screenMarker.selectable = true
screenMarker
}