diff --git a/README.md b/README.md index 73c20f4..0d292ec 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Explore the example applications to see OpenMapView in action: - [Example11MapTypes](examples/Example11MapTypes) - Switching between 5 map types (Normal, Terrain, Humanitarian, Cycle, None) - [Example12Toolbar](examples/Example12Toolbar) - Open location in external map apps via geo: URI with OpenStreetMap browser fallback -![Example05Camera Demo](examples/Example05Camera/screenshot.gif) +![Example01Pan Demo](examples/Example01Pan/screenshot.gif) ## Documentation diff --git a/openmapview/src/main/kotlin/de/afarber/openmapview/MapController.kt b/openmapview/src/main/kotlin/de/afarber/openmapview/MapController.kt index 294ecda..f4da41f 100644 --- a/openmapview/src/main/kotlin/de/afarber/openmapview/MapController.kt +++ b/openmapview/src/main/kotlin/de/afarber/openmapview/MapController.kt @@ -1305,8 +1305,8 @@ class MapController( private fun drawPolylines( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, ) { val paint = Paint() paint.style = Paint.Style.STROKE @@ -1343,8 +1343,8 @@ class MapController( private fun drawPolygons( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, ) { val fillPaint = Paint() fillPaint.style = Paint.Style.FILL @@ -1410,8 +1410,8 @@ class MapController( private fun drawCircles( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, ) { val fillPaint = Paint() fillPaint.style = Paint.Style.FILL @@ -1465,8 +1465,8 @@ class MapController( private fun drawMarkers( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, ) { for (marker in markers) { // Skip invisible markers @@ -1503,8 +1503,8 @@ class MapController( private fun drawGroundOverlay( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, groundOverlay: GroundOverlay, ) { val bitmap = loadBitmap(groundOverlay.image) @@ -1583,8 +1583,8 @@ class MapController( private fun drawPolygonsByZIndex( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, zIndex: Float, sortedPolygons: List, ) { @@ -1649,8 +1649,8 @@ class MapController( private fun drawPolylinesByZIndex( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, zIndex: Float, sortedPolylines: List, ) { @@ -1689,8 +1689,8 @@ class MapController( private fun drawCirclesByZIndex( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, zIndex: Float, sortedCircles: List, ) { @@ -1725,8 +1725,8 @@ class MapController( private fun drawMarkersByZIndex( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, zIndex: Float, sortedMarkers: List, ) { @@ -1754,8 +1754,8 @@ class MapController( private fun drawInfoWindows( canvas: Canvas, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, ) { val backgroundPaint = Paint().apply { @@ -1888,8 +1888,8 @@ class MapController( private fun drawTileOverlay( canvas: Canvas, visibleTiles: List, - centerPixelX: Double, - centerPixelY: Double, + centerPixelX: Float, + centerPixelY: Float, overlay: TileOverlay, ) { val cache = overlayTileCaches[overlay.id] ?: return diff --git a/openmapview/src/main/kotlin/de/afarber/openmapview/Projection.kt b/openmapview/src/main/kotlin/de/afarber/openmapview/Projection.kt index c2c40f6..8f90feb 100644 --- a/openmapview/src/main/kotlin/de/afarber/openmapview/Projection.kt +++ b/openmapview/src/main/kotlin/de/afarber/openmapview/Projection.kt @@ -71,8 +71,8 @@ class Projection val adjustedScreenX = screenX - paddingOffsetX val adjustedScreenY = screenY - paddingOffsetY - val pixelX = (centerPixelX + (adjustedScreenX - viewWidth / 2 + panOffsetX).toDouble()).toInt() - val pixelY = (centerPixelY + (adjustedScreenY - viewHeight / 2 + panOffsetY).toDouble()).toInt() + val pixelX = (centerPixelX + adjustedScreenX - viewWidth / 2 + panOffsetX).toInt() + val pixelY = (centerPixelY + adjustedScreenY - viewHeight / 2 + panOffsetY).toInt() return ProjectionUtils.pixelToLatLng(pixelX, pixelY, zoom.toInt()) } diff --git a/openmapview/src/main/kotlin/de/afarber/openmapview/ProjectionUtils.kt b/openmapview/src/main/kotlin/de/afarber/openmapview/ProjectionUtils.kt index 0264579..8b777f5 100644 --- a/openmapview/src/main/kotlin/de/afarber/openmapview/ProjectionUtils.kt +++ b/openmapview/src/main/kotlin/de/afarber/openmapview/ProjectionUtils.kt @@ -62,12 +62,12 @@ internal object ProjectionUtils { fun latLngToPixel( latLng: LatLng, zoom: Int, - ): Pair { + ): Pair { val n = 2.0.pow(zoom) val xPixel = (latLng.longitude + 180.0) / 360.0 * n * TILE_SIZE val latRad = latLng.latitude * PI / 180.0 val yPixel = (1.0 - ln(tan(latRad) + 1.0 / cos(latRad)) / PI) / 2.0 * n * TILE_SIZE - return Pair(xPixel, yPixel) + return Pair(xPixel.toFloat(), yPixel.toFloat()) } /** diff --git a/openmapview/src/main/kotlin/de/afarber/openmapview/TileOverlay.kt b/openmapview/src/main/kotlin/de/afarber/openmapview/TileOverlay.kt index edf90d5..ef45f43 100644 --- a/openmapview/src/main/kotlin/de/afarber/openmapview/TileOverlay.kt +++ b/openmapview/src/main/kotlin/de/afarber/openmapview/TileOverlay.kt @@ -60,7 +60,7 @@ data class TileOverlay( val fadeIn: Boolean = false, val tag: Any? = null, ) { - internal val id: String = "tileoverlay_${System.nanoTime()}_${System.identityHashCode(this)}" + internal val id: String = "tileOverlay_${System.nanoTime()}_${System.identityHashCode(this)}" init { require(transparency in 0f..1f) { diff --git a/openmapview/src/test/kotlin/de/afarber/openmapview/ProjectionTest.kt b/openmapview/src/test/kotlin/de/afarber/openmapview/ProjectionTest.kt index ee90421..d128b91 100644 --- a/openmapview/src/test/kotlin/de/afarber/openmapview/ProjectionTest.kt +++ b/openmapview/src/test/kotlin/de/afarber/openmapview/ProjectionTest.kt @@ -11,34 +11,35 @@ import org.junit.Assert.assertEquals import org.junit.Test class ProjectionTest { - private val epsilon = 0.0001 + private val epsilonFloat = 0.0001f + private val epsilonDouble = 0.0001 @Test fun testLatLngToPixel_Equator() { // At zoom 0, equator center should be at (128, 128) val (x, y) = ProjectionUtils.latLngToPixel(LatLng(0.0, 0.0), 0) - assertEquals(128.0, x, epsilon) - assertEquals(128.0, y, epsilon) + assertEquals(128.0f, x, epsilonFloat) + assertEquals(128.0f, y, epsilonFloat) } @Test fun testLatLngToPixel_NullIsland() { // Null Island (0,0) at different zooms val zoom1 = ProjectionUtils.latLngToPixel(LatLng(0.0, 0.0), 1) - assertEquals(256.0, zoom1.first, epsilon) - assertEquals(256.0, zoom1.second, epsilon) + assertEquals(256.0f, zoom1.first, epsilonFloat) + assertEquals(256.0f, zoom1.second, epsilonFloat) val zoom2 = ProjectionUtils.latLngToPixel(LatLng(0.0, 0.0), 2) - assertEquals(512.0, zoom2.first, epsilon) - assertEquals(512.0, zoom2.second, epsilon) + assertEquals(512.0f, zoom2.first, epsilonFloat) + assertEquals(512.0f, zoom2.second, epsilonFloat) } @Test fun testPixelToLatLng_Equator() { // At zoom 0, pixel (128, 128) should be equator center val latLng = ProjectionUtils.pixelToLatLng(128, 128, 0) - assertEquals(0.0, latLng.latitude, epsilon) - assertEquals(0.0, latLng.longitude, epsilon) + assertEquals(0.0, latLng.latitude, epsilonDouble) + assertEquals(0.0, latLng.longitude, epsilonDouble) } @Test @@ -50,8 +51,8 @@ class ProjectionTest { val (x, y) = ProjectionUtils.latLngToPixel(original, zoom) val result = ProjectionUtils.pixelToLatLng(x.toInt(), y.toInt(), zoom) - assertEquals(original.latitude, result.latitude, epsilon) - assertEquals(original.longitude, result.longitude, epsilon) + assertEquals(original.latitude, result.latitude, epsilonDouble) + assertEquals(original.longitude, result.longitude, epsilonDouble) } @Test @@ -91,8 +92,8 @@ class ProjectionTest { // +180° should be at right edge (512), -180° at left edge (0) // They represent the same meridian but wrap around - assertEquals(512.0, positive.first, epsilon) - assertEquals(0.0, negative.first, epsilon) + assertEquals(512.0f, positive.first, epsilonFloat) + assertEquals(0.0f, negative.first, epsilonFloat) } @Test