Skip to content

Commit

Permalink
Add overlay support to map layers
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Oct 13, 2024
1 parent 5b9b96b commit 7209f92
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ abstract class BasePhotoMapView : EnhancedImageView, IMapView {
layers.forEach { it.draw(drawer, this) }
}

override fun drawOverlay() {
super.drawOverlay()
layers.forEach { it.drawOverlay(drawer, this) }
}

open fun showMap(map: PhotoMap) {
this.map = map
val rotation = map.calibration.rotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ class MapDistanceLayer(private val onPathChanged: (points: List<Coordinate>) ->
pointLayer.draw(drawer, map)
}

override fun drawOverlay(
drawer: ICanvasDrawer,
map: IMapView
) {
if (!isEnabled) {
return
}

pathLayer.drawOverlay(drawer, map)
pointLayer.drawOverlay(drawer, map)
}

override fun invalidate() {
pointLayer.invalidate()
pathLayer.invalidate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class RadarCompassView : BaseCompassView, IMapView {
pop()
}

private fun drawOverlays() {
layers.forEach { it.drawOverlay(this, this) }
}

private fun drawCompass() {
imageMode(ImageMode.Center)

Expand Down Expand Up @@ -207,6 +211,7 @@ class RadarCompassView : BaseCompassView, IMapView {
drawLayers()
drawCompassLayers()
pop()
drawOverlays()
}

override fun draw(reference: IMappableReferencePoint, size: Int?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ open class BaseLayer : ILayer {
}
}

override fun drawOverlay(
drawer: ICanvasDrawer,
map: IMapView
) {
// Do nothing
}

override fun invalidate() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ import com.kylecorry.andromeda.canvas.ICanvasDrawer
import com.kylecorry.andromeda.core.units.PixelCoordinate

interface ILayer {
/**
* Draw the layer on the map.
* Transforms are already applied to the canvas.
*/
fun draw(drawer: ICanvasDrawer, map: IMapView)

/**
* Draw the overlay on the map.
* This is drawn on top of the map and is not transformed.
*/
fun drawOverlay(drawer: ICanvasDrawer, map: IMapView)

/**
* Invalidate the layer
*/
fun invalidate()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ class PathLayer : ILayer, IPathLayer {
drawer.noPathEffect()
}

override fun drawOverlay(
drawer: ICanvasDrawer,
map: IMapView
) {
// Do nothing
}

private fun renderInBackground(renderer: IRenderedPathFactory) {
renderInProgress = true
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class PathView(context: Context, attrs: AttributeSet? = null) : CanvasView(conte

drawLayers()
drawScale()
drawOverlays()
}

private fun drawLayers() {
Expand Down Expand Up @@ -186,6 +187,10 @@ class PathView(context: Context, attrs: AttributeSet? = null) : CanvasView(conte
return center.plus(Distance.meters(distance), Bearing(angle + 90))
}

private fun drawOverlays() {
layers.forEach { it.drawOverlay(this, this) }
}

private fun drawScale() {
noFill()
stroke(Color.WHITE)
Expand Down Expand Up @@ -227,8 +232,8 @@ class PathView(context: Context, attrs: AttributeSet? = null) : CanvasView(conte
}

@Suppress("MemberVisibilityCanBePrivate")
fun zoomTo(newScale: Float){
if (newScale == scale){
fun zoomTo(newScale: Float) {
if (newScale == scale) {
return
}
zoom(newScale / scale)
Expand Down

0 comments on commit 7209f92

Please sign in to comment.