Skip to content

Commit

Permalink
feat: add getZoom and setZoom function support for Android Auto (#…
Browse files Browse the repository at this point in the history
…3037)

Co-authored-by: thanhdt1998 <[email protected]>
  • Loading branch information
thanhdang198 and thanhdt-vietmap authored Nov 21, 2024
1 parent a44bcb1 commit 06fb5c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,24 @@ public void scrollBy(float x, float y, long duration) {
nativeMapView.moveBy(x, y, duration);
}

/**
* Returns the current zoom level.
*/
public double getZoom() {
return nativeMapView.getZoom();
}

/**
* Zooms the camera to the specified level.
* @param zoom The zoom level to which the camera should move.
* @param focalPoint The point around which to zoom.
* @param duration The duration for the zoom animation
*/
public void setZoom(double zoom, @NonNull PointF focalPoint, long duration ) {
notifyDeveloperAnimationListeners();
nativeMapView.setZoom(zoom, focalPoint, duration);
}

//
// Reset North
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.maplibre.android.maps

import android.content.Context
import android.graphics.PointF
import org.maplibre.android.MapLibreInjector
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.camera.CameraUpdateFactory
Expand Down Expand Up @@ -244,4 +245,19 @@ class MapLibreMapTest {
maplibreMap.onFinishLoadingStyle()
verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) }
}

@Test
fun testGetZoom() {
maplibreMap.zoom
verify { nativeMapView.zoom }
assertEquals(maplibreMap.zoom, 0.0, 0.0)
}

@Test
fun testSetZoom() {
val target = PointF(100f, 100f)
maplibreMap.setZoom(2.0, target, 0)
verify { developerAnimationListener.onDeveloperAnimationStarted() }
verify { nativeMapView.setZoom(2.0, target, 0) }
}
}

0 comments on commit 06fb5c4

Please sign in to comment.