From 72d4b1005a885fee7b44bdfcdffa830b27c7d12b Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Thu, 13 Jan 2022 02:54:42 -0600 Subject: Added labels for markers and disabled clustering until we figure out how to combine it with marker labels --- .../TrackerMap/android/map/MapFragment.kt | 70 +++++++++++++--------- .../android/map/MarkerTransformations.kt | 3 + androidApp/src/main/res/values/colors.xml | 3 + androidApp/src/main/res/values/dimen.xml | 4 ++ 4 files changed, 53 insertions(+), 27 deletions(-) (limited to 'androidApp') 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 9b4d24a..b8fbc57 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 @@ -27,6 +27,7 @@ class MapFragment : GlobeMapFragment() { data class Marker( val id: Int, + val name: String, val latitude: Double, val longitude: Double, val type: MarkerType = MarkerType.DEFAULT @@ -74,20 +75,6 @@ class MapFragment : GlobeMapFragment() { loader = QuadImageLoader(params, tileInfo, baseControl) loader?.setImageFormat(RenderController.ImageFormat.MaplyImageUShort565) - val clusterGenerator = BasicClusterGenerator( - intArrayOf( - Color.argb(255, 255, 255, 255) - ), 0, Point2d(64.0, 64.0), baseControl, activity - ) - clusterGenerator.cacheBitmaps(true) - clusterGenerator.setExponentBase(2.5) - clusterGenerator.setTextColor(Color.BLACK) - clusterGenerator.setLayoutSize(Point2d(80.0, 80.0)) - clusterGenerator.setSelectable(false) - - baseControl.clearClusterGenerators() - baseControl.addClusterGenerator(clusterGenerator) - val latitude = 23.191 val longitude = -100.36 focusOn(latitude, longitude, zoom = 0.4, animated = false) @@ -143,10 +130,22 @@ class MapFragment : GlobeMapFragment() { Point2d.FromDegrees(marker.longitude, marker.latitude) }.toTypedArray() + val fontSize = context?.resources?.getDimensionPixelSize(R.dimen.marker_label_text_size) + val reportColor = ContextCompat.getColor(context!!, R.color.colorReport) + val labelColor = ContextCompat.getColor(context!!, R.color.colorMarkerLabel) + val labelBgColor = ContextCompat.getColor(context!!, R.color.bgColorMarkerLabel) + val vectorInfo = VectorInfo() - vectorInfo.setColor(ContextCompat.getColor(context!!, R.color.colorReport)) + vectorInfo.setColor(reportColor) vectorInfo.setLineWidth(20.0f) + val labelInfo = LabelInfo() + labelInfo.textColor = labelColor + labelInfo.backgroundColor = labelBgColor + fontSize?.let { + labelInfo.fontSize = it.toFloat() + } + /* Draw markers for positions */ val screenMarkers = markers.mapIndexed { i, marker -> val screenMarker = ScreenMarker() @@ -169,24 +168,36 @@ class MapFragment : GlobeMapFragment() { } else Point2d(144.0, 144.0) screenMarker.userObject = marker.id screenMarker.selectable = true - if (!isReport) { - screenMarker.layoutImportance = 1.0f - } screenMarker } - val markerInfo = MarkerInfo() - if (!isReport) { - markerInfo.setClusterGroup(0) - } - objects.add(mapControl.addScreenMarkers( screenMarkers, - markerInfo, + MarkerInfo(), ThreadMode.ThreadAny )) + /* Add labels for markers */ + if (!isReport && markers.isNotEmpty()) { + val screenLabels = markers.map { marker -> + val label = ScreenLabel() + label.layoutImportance = Float.MAX_VALUE + label.text = if (marker.name.length >= 20) { + marker.name.substring(0 until 20) + "..." + } else marker.name + label.loc = Point2d.FromDegrees(marker.longitude, marker.latitude) + label.offset = Point2d(0.0, 92.0) + label + } + + objects.add(mapControl.addScreenLabels( + screenLabels, + labelInfo, + ThreadMode.ThreadAny + )) + } + /* Draw polyline for report */ if (isReport && markers.isNotEmpty()) { val vector = VectorObject() @@ -219,14 +230,19 @@ class MapFragment : GlobeMapFragment() { clear(true) - val color = ContextCompat.getColor(context!!, R.color.colorGeofence) + val fontSize = context?.resources?.getDimensionPixelSize(R.dimen.marker_label_text_size) + val colorFill = ContextCompat.getColor(context!!, R.color.colorGeofence) + val colorLabel = ContextCompat.getColor(context!!, R.color.colorGeofenceLabel) val vectorInfo = VectorInfo() - vectorInfo.setColor(color) + vectorInfo.setColor(colorFill) vectorInfo.setLineWidth(10.0f) val labelInfo = LabelInfo() - labelInfo.textColor = color + labelInfo.textColor = colorLabel + fontSize?.let { + labelInfo.fontSize = it.toFloat() + } val shapes = mutableListOf() val vectors = mutableListOf() diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt index fcde58d..b1d52fb 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt @@ -13,6 +13,7 @@ object MarkerTransformations { return MapFragment.Marker( unit.position!!.id!!, + unit.device.name, unit.position!!.latitude!!, unit.position!!.longitude!!, categoryToMarkerType(unit.device.category ?: "") @@ -26,6 +27,7 @@ object MarkerTransformations { return MapFragment.Marker( position.id!!, + "", position.latitude!!, position.longitude!! ) @@ -38,6 +40,7 @@ object MarkerTransformations { return MapFragment.Marker( stop.deviceId!!, + stop.deviceName!!, stop.lat!!, stop.lon!! ) diff --git a/androidApp/src/main/res/values/colors.xml b/androidApp/src/main/res/values/colors.xml index ee5d167..b241148 100644 --- a/androidApp/src/main/res/values/colors.xml +++ b/androidApp/src/main/res/values/colors.xml @@ -6,7 +6,10 @@ #FDFDFD #ECEFF3 + #656A74 + #FFFFFF #1976D2 + #1976D2 #388E3C #388E3C diff --git a/androidApp/src/main/res/values/dimen.xml b/androidApp/src/main/res/values/dimen.xml index 2d0dcc3..a016dbd 100644 --- a/androidApp/src/main/res/values/dimen.xml +++ b/androidApp/src/main/res/values/dimen.xml @@ -21,6 +21,10 @@ 12dp 8dp + + 11sp + 11sp + 8dp 16dp -- cgit v1.2.3