Skip to content

Commit b8e2bb3

Browse files
authored
Fix camelCase naming and convert pixel coordinates from Double to Float (#12)
1 parent f83372b commit b8e2bb3

File tree

6 files changed

+42
-41
lines changed

6 files changed

+42
-41
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Explore the example applications to see OpenMapView in action:
7373
- [Example11MapTypes](examples/Example11MapTypes) - Switching between 5 map types (Normal, Terrain, Humanitarian, Cycle, None)
7474
- [Example12Toolbar](examples/Example12Toolbar) - Open location in external map apps via geo: URI with OpenStreetMap browser fallback
7575

76-
![Example05Camera Demo](examples/Example05Camera/screenshot.gif)
76+
![Example01Pan Demo](examples/Example01Pan/screenshot.gif)
7777

7878
## Documentation
7979

openmapview/src/main/kotlin/de/afarber/openmapview/MapController.kt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,8 @@ class MapController(
13051305

13061306
private fun drawPolylines(
13071307
canvas: Canvas,
1308-
centerPixelX: Double,
1309-
centerPixelY: Double,
1308+
centerPixelX: Float,
1309+
centerPixelY: Float,
13101310
) {
13111311
val paint = Paint()
13121312
paint.style = Paint.Style.STROKE
@@ -1343,8 +1343,8 @@ class MapController(
13431343

13441344
private fun drawPolygons(
13451345
canvas: Canvas,
1346-
centerPixelX: Double,
1347-
centerPixelY: Double,
1346+
centerPixelX: Float,
1347+
centerPixelY: Float,
13481348
) {
13491349
val fillPaint = Paint()
13501350
fillPaint.style = Paint.Style.FILL
@@ -1410,8 +1410,8 @@ class MapController(
14101410

14111411
private fun drawCircles(
14121412
canvas: Canvas,
1413-
centerPixelX: Double,
1414-
centerPixelY: Double,
1413+
centerPixelX: Float,
1414+
centerPixelY: Float,
14151415
) {
14161416
val fillPaint = Paint()
14171417
fillPaint.style = Paint.Style.FILL
@@ -1465,8 +1465,8 @@ class MapController(
14651465

14661466
private fun drawMarkers(
14671467
canvas: Canvas,
1468-
centerPixelX: Double,
1469-
centerPixelY: Double,
1468+
centerPixelX: Float,
1469+
centerPixelY: Float,
14701470
) {
14711471
for (marker in markers) {
14721472
// Skip invisible markers
@@ -1503,8 +1503,8 @@ class MapController(
15031503

15041504
private fun drawGroundOverlay(
15051505
canvas: Canvas,
1506-
centerPixelX: Double,
1507-
centerPixelY: Double,
1506+
centerPixelX: Float,
1507+
centerPixelY: Float,
15081508
groundOverlay: GroundOverlay,
15091509
) {
15101510
val bitmap = loadBitmap(groundOverlay.image)
@@ -1583,8 +1583,8 @@ class MapController(
15831583

15841584
private fun drawPolygonsByZIndex(
15851585
canvas: Canvas,
1586-
centerPixelX: Double,
1587-
centerPixelY: Double,
1586+
centerPixelX: Float,
1587+
centerPixelY: Float,
15881588
zIndex: Float,
15891589
sortedPolygons: List<Polygon>,
15901590
) {
@@ -1649,8 +1649,8 @@ class MapController(
16491649

16501650
private fun drawPolylinesByZIndex(
16511651
canvas: Canvas,
1652-
centerPixelX: Double,
1653-
centerPixelY: Double,
1652+
centerPixelX: Float,
1653+
centerPixelY: Float,
16541654
zIndex: Float,
16551655
sortedPolylines: List<Polyline>,
16561656
) {
@@ -1689,8 +1689,8 @@ class MapController(
16891689

16901690
private fun drawCirclesByZIndex(
16911691
canvas: Canvas,
1692-
centerPixelX: Double,
1693-
centerPixelY: Double,
1692+
centerPixelX: Float,
1693+
centerPixelY: Float,
16941694
zIndex: Float,
16951695
sortedCircles: List<Circle>,
16961696
) {
@@ -1725,8 +1725,8 @@ class MapController(
17251725

17261726
private fun drawMarkersByZIndex(
17271727
canvas: Canvas,
1728-
centerPixelX: Double,
1729-
centerPixelY: Double,
1728+
centerPixelX: Float,
1729+
centerPixelY: Float,
17301730
zIndex: Float,
17311731
sortedMarkers: List<Marker>,
17321732
) {
@@ -1754,8 +1754,8 @@ class MapController(
17541754

17551755
private fun drawInfoWindows(
17561756
canvas: Canvas,
1757-
centerPixelX: Double,
1758-
centerPixelY: Double,
1757+
centerPixelX: Float,
1758+
centerPixelY: Float,
17591759
) {
17601760
val backgroundPaint =
17611761
Paint().apply {
@@ -1888,8 +1888,8 @@ class MapController(
18881888
private fun drawTileOverlay(
18891889
canvas: Canvas,
18901890
visibleTiles: List<TileCoordinate>,
1891-
centerPixelX: Double,
1892-
centerPixelY: Double,
1891+
centerPixelX: Float,
1892+
centerPixelY: Float,
18931893
overlay: TileOverlay,
18941894
) {
18951895
val cache = overlayTileCaches[overlay.id] ?: return

openmapview/src/main/kotlin/de/afarber/openmapview/Projection.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class Projection
7171
val adjustedScreenX = screenX - paddingOffsetX
7272
val adjustedScreenY = screenY - paddingOffsetY
7373

74-
val pixelX = (centerPixelX + (adjustedScreenX - viewWidth / 2 + panOffsetX).toDouble()).toInt()
75-
val pixelY = (centerPixelY + (adjustedScreenY - viewHeight / 2 + panOffsetY).toDouble()).toInt()
74+
val pixelX = (centerPixelX + adjustedScreenX - viewWidth / 2 + panOffsetX).toInt()
75+
val pixelY = (centerPixelY + adjustedScreenY - viewHeight / 2 + panOffsetY).toInt()
7676

7777
return ProjectionUtils.pixelToLatLng(pixelX, pixelY, zoom.toInt())
7878
}

openmapview/src/main/kotlin/de/afarber/openmapview/ProjectionUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ internal object ProjectionUtils {
6262
fun latLngToPixel(
6363
latLng: LatLng,
6464
zoom: Int,
65-
): Pair<Double, Double> {
65+
): Pair<Float, Float> {
6666
val n = 2.0.pow(zoom)
6767
val xPixel = (latLng.longitude + 180.0) / 360.0 * n * TILE_SIZE
6868
val latRad = latLng.latitude * PI / 180.0
6969
val yPixel = (1.0 - ln(tan(latRad) + 1.0 / cos(latRad)) / PI) / 2.0 * n * TILE_SIZE
70-
return Pair(xPixel, yPixel)
70+
return Pair(xPixel.toFloat(), yPixel.toFloat())
7171
}
7272

7373
/**

openmapview/src/main/kotlin/de/afarber/openmapview/TileOverlay.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ data class TileOverlay(
6060
val fadeIn: Boolean = false,
6161
val tag: Any? = null,
6262
) {
63-
internal val id: String = "tileoverlay_${System.nanoTime()}_${System.identityHashCode(this)}"
63+
internal val id: String = "tileOverlay_${System.nanoTime()}_${System.identityHashCode(this)}"
6464

6565
init {
6666
require(transparency in 0f..1f) {

openmapview/src/test/kotlin/de/afarber/openmapview/ProjectionTest.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,35 @@ import org.junit.Assert.assertEquals
1111
import org.junit.Test
1212

1313
class ProjectionTest {
14-
private val epsilon = 0.0001
14+
private val epsilonFloat = 0.0001f
15+
private val epsilonDouble = 0.0001
1516

1617
@Test
1718
fun testLatLngToPixel_Equator() {
1819
// At zoom 0, equator center should be at (128, 128)
1920
val (x, y) = ProjectionUtils.latLngToPixel(LatLng(0.0, 0.0), 0)
20-
assertEquals(128.0, x, epsilon)
21-
assertEquals(128.0, y, epsilon)
21+
assertEquals(128.0f, x, epsilonFloat)
22+
assertEquals(128.0f, y, epsilonFloat)
2223
}
2324

2425
@Test
2526
fun testLatLngToPixel_NullIsland() {
2627
// Null Island (0,0) at different zooms
2728
val zoom1 = ProjectionUtils.latLngToPixel(LatLng(0.0, 0.0), 1)
28-
assertEquals(256.0, zoom1.first, epsilon)
29-
assertEquals(256.0, zoom1.second, epsilon)
29+
assertEquals(256.0f, zoom1.first, epsilonFloat)
30+
assertEquals(256.0f, zoom1.second, epsilonFloat)
3031

3132
val zoom2 = ProjectionUtils.latLngToPixel(LatLng(0.0, 0.0), 2)
32-
assertEquals(512.0, zoom2.first, epsilon)
33-
assertEquals(512.0, zoom2.second, epsilon)
33+
assertEquals(512.0f, zoom2.first, epsilonFloat)
34+
assertEquals(512.0f, zoom2.second, epsilonFloat)
3435
}
3536

3637
@Test
3738
fun testPixelToLatLng_Equator() {
3839
// At zoom 0, pixel (128, 128) should be equator center
3940
val latLng = ProjectionUtils.pixelToLatLng(128, 128, 0)
40-
assertEquals(0.0, latLng.latitude, epsilon)
41-
assertEquals(0.0, latLng.longitude, epsilon)
41+
assertEquals(0.0, latLng.latitude, epsilonDouble)
42+
assertEquals(0.0, latLng.longitude, epsilonDouble)
4243
}
4344

4445
@Test
@@ -50,8 +51,8 @@ class ProjectionTest {
5051
val (x, y) = ProjectionUtils.latLngToPixel(original, zoom)
5152
val result = ProjectionUtils.pixelToLatLng(x.toInt(), y.toInt(), zoom)
5253

53-
assertEquals(original.latitude, result.latitude, epsilon)
54-
assertEquals(original.longitude, result.longitude, epsilon)
54+
assertEquals(original.latitude, result.latitude, epsilonDouble)
55+
assertEquals(original.longitude, result.longitude, epsilonDouble)
5556
}
5657

5758
@Test
@@ -91,8 +92,8 @@ class ProjectionTest {
9192

9293
// +180° should be at right edge (512), -180° at left edge (0)
9394
// They represent the same meridian but wrap around
94-
assertEquals(512.0, positive.first, epsilon)
95-
assertEquals(0.0, negative.first, epsilon)
95+
assertEquals(512.0f, positive.first, epsilonFloat)
96+
assertEquals(0.0f, negative.first, epsilonFloat)
9697
}
9798

9899
@Test

0 commit comments

Comments
 (0)