Start working on bounding box display

This commit is contained in:
Danila Fedorin 2020-05-12 00:51:53 -07:00
parent 9983753912
commit 246d43be80
3 changed files with 57 additions and 0 deletions

View File

@ -1,18 +1,66 @@
package com.danilafe.fencelessgrazing
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.danilafe.fencelessgrazing.model.CollarPos
import com.danilafe.fencelessgrazing.model.Polygon
import org.osmdroid.util.GeoPoint
import org.osmdroid.views.MapView
class CollarDetailActivity : AppCompatActivity() {
private lateinit var token: String
private var collarId: Int = -1
private lateinit var map: MapView
private lateinit var mapPolygon: org.osmdroid.views.overlay.Polygon
private var boundingBox: Polygon? = null
set(newValue) {
if(newValue != null) updateBoundingBox(field, newValue)
else clearBoundingBox()
field = newValue
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_collar_detail)
token = intent.getStringExtra("token")!!
collarId = intent.getIntExtra("identifier", -1)
map = findViewById(R.id.detailMap)
mapPolygon = org.osmdroid.views.overlay.Polygon(map)
configureMapPolygon()
}
private fun configureMapPolygon() {
mapPolygon.fillPaint.color = Color.CYAN
mapPolygon.fillPaint.alpha = 127
mapPolygon.outlinePaint.strokeWidth = 0.0f
mapPolygon.title = "Valid Grazing Area"
}
private fun updateBoundingBox(oldValue: Polygon?, polygon: Polygon) {
if(oldValue == null) map.overlays.add(mapPolygon)
val points = polygon.dataPoints.map { GeoPoint(it.longitude.toDouble(), it.latitude.toDouble()) }
val polygonPoints = points.toMutableList()
polygonPoints.add(polygonPoints[0])
mapPolygon.points = polygonPoints
}
private fun clearBoundingBox() {
map.overlays.remove(mapPolygon)
}
override fun onPause() {
super.onPause()
map.onPause()
}
override fun onResume() {
super.onResume()
map.onResume()
}
}

View File

@ -1,2 +1,3 @@
package com.danilafe.fencelessgrazing.model
data class Polygon(val dataPoints : List<CollarPos>)

View File

@ -5,5 +5,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CollarDetailActivity">
<org.osmdroid.views.MapView
android:id="@+id/detailMap"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>