diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-10-17 14:51:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-17 14:51:39 +0200 |
commit | 1bee9d34f548f194a4b34460a4c16ccd13c088ef (patch) | |
tree | d706bc4bd70cc933920e4d3d753b09305ba2653c /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java | |
parent | d22d8a6c9b3e6efa12f1fbcc57d6795e1479df40 (diff) | |
download | qtlocation-mapboxgl-1bee9d34f548f194a4b34460a4c16ccd13c088ef.tar.gz |
Reusable point fromScreenLocation (#6652)
* Fixed bug where fromScreenLocation would modify the actual Point being passed in
* [android] - move reused point to Projection class, migrated screen density logic to projection
fixup code to be unit testable
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java index 17d4a7c657..e06ed38433 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java @@ -15,10 +15,15 @@ import com.mapbox.mapboxsdk.geometry.VisibleRegion; */ public class Projection { - private MapView mapView; + private final MapView mapView; + private final float screenDensity; + private final PointF screenLocationPoint; Projection(@NonNull MapView mapView) { this.mapView = mapView; + this.screenLocationPoint = new PointF(); + this.screenDensity = mapView.getContext() != null ? /* return default if unit test */ + mapView.getContext().getResources().getDisplayMetrics().density : 1.0f; } /** @@ -45,7 +50,8 @@ public class Projection { * the given screen point does not intersect the ground plane. */ public LatLng fromScreenLocation(PointF point) { - return mapView.fromScreenLocation(point); + screenLocationPoint.set(point.x / screenDensity, point.y / screenDensity); + return mapView.fromNativeScreenLocation(screenLocationPoint); } /** @@ -84,7 +90,9 @@ public class Projection { * @return A Point representing the screen location in screen pixels. */ public PointF toScreenLocation(LatLng location) { - return mapView.toScreenLocation(location); + PointF pointF = mapView.toNativeScreenLocation(location); + pointF.set(pointF.x * screenDensity, pointF.y * screenDensity); + return pointF; } /** |