Start working on bounding box display
This commit is contained in:
parent
9983753912
commit
246d43be80
|
@ -1,18 +1,66 @@
|
||||||
package com.danilafe.fencelessgrazing
|
package com.danilafe.fencelessgrazing
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
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() {
|
class CollarDetailActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var token: String
|
private lateinit var token: String
|
||||||
private var collarId: Int = -1
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_collar_detail)
|
setContentView(R.layout.activity_collar_detail)
|
||||||
|
|
||||||
token = intent.getStringExtra("token")!!
|
token = intent.getStringExtra("token")!!
|
||||||
collarId = intent.getIntExtra("identifier", -1)
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
package com.danilafe.fencelessgrazing.model
|
package com.danilafe.fencelessgrazing.model
|
||||||
|
|
||||||
|
data class Polygon(val dataPoints : List<CollarPos>)
|
|
@ -5,5 +5,13 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".CollarDetailActivity">
|
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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user