summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-02-03 17:26:09 +0100
committerTobrun <tobrun@mapbox.com>2016-02-04 12:08:39 +0100
commitaa05cba0df0645b7e65a3cff8724d8adb3b922ce (patch)
treec2a1daf64efac46e09e4efa5d849bbe01964616a /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
parentbc1f4b1fc0d96ecd544047db54d4abbffc45ee19 (diff)
downloadqtlocation-mapboxgl-aa05cba0df0645b7e65a3cff8724d8adb3b922ce.tar.gz
[android] #3758 - Projection / Visible Region implementation.
[android] #3758 - add VisibleRegion + unit tests, removed boundingbox, cleanup jni, cleanup test app, renamed CoordinateSpan to LatLng.
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.java72
1 files changed, 72 insertions, 0 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
new file mode 100644
index 0000000000..e53d430b69
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -0,0 +1,72 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.graphics.PointF;
+import android.support.annotation.NonNull;
+
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.geometry.VisibleRegion;
+
+/**
+ * A projection is used to translate between on screen location and geographic coordinates on
+ * the surface of the Earth (LatLng). Screen location is in screen pixels (not display pixels)
+ * with respect to the top left corner of the map (and not necessarily of the whole screen).
+ */
+public class Projection {
+
+ private MapView mMapView;
+
+ Projection(@NonNull MapView mapView) {
+ this.mMapView = mapView;
+ }
+
+ /**
+ * Returns the geographic location that corresponds to a screen location.
+ * The screen location is specified in screen pixels (not display pixels) relative to the
+ * top left of the map (not the top left of the whole screen).
+ *
+ * @param point A Point on the screen in screen pixels.
+ * @return The LatLng corresponding to the point on the screen, or null if the ray through
+ * the given screen point does not intersect the ground plane.
+ */
+ public LatLng fromScreenLocation(PointF point) {
+ return mMapView.fromScreenLocation(point);
+ }
+
+ /**
+ * Gets a projection of the viewing frustum for converting between screen coordinates and
+ * geo-latitude/longitude coordinates.
+ *
+ * @return The projection of the viewing frustum in its current state.
+ */
+ public VisibleRegion getVisibleRegion() {
+ LatLngBounds.Builder builder = new LatLngBounds.Builder();
+
+ int viewportWidth = mMapView.getWidth();
+ int viewportHeight = mMapView.getHeight();
+
+ LatLng topLeft = fromScreenLocation(new PointF(0, 0));
+ LatLng topRight = fromScreenLocation(new PointF(viewportWidth, 0));
+ LatLng bottomRight = fromScreenLocation(new PointF(viewportWidth, viewportHeight));
+ LatLng bottomLeft = fromScreenLocation(new PointF(0, viewportHeight));
+
+ builder.include(topLeft)
+ .include(topRight)
+ .include(bottomRight)
+ .include(bottomLeft);
+
+ return new VisibleRegion(topLeft,topRight,bottomLeft,bottomRight,builder.build());
+ }
+
+ /**
+ * Returns a screen location that corresponds to a geographical coordinate (LatLng).
+ * The screen location is in screen pixels (not display pixels) relative to the top left
+ * of the map (not of the whole screen).
+ *
+ * @param location A LatLng on the map to convert to a screen location.
+ * @return A Point representing the screen location in screen pixels.
+ */
+ public PointF toScreenLocation(LatLng location) {
+ return mMapView.toScreenLocation(location);
+ }
+}