From e7398c16c133e74274ffeda4b5b2994816fcf121 Mon Sep 17 00:00:00 2001 From: tobrun Date: Sun, 6 Sep 2015 16:37:34 +0200 Subject: [PATCH] Added "Improve this map" functionality, current zoom level, center latitude and longitude will be parsed in to the url of improve this map. --- .../com/mapbox/mapboxgl/views/MapView.java | 22 ++++++++++++++----- .../src/main/res/values/arrays.xml | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java index 5a07365c4..71121b7aa 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java @@ -120,6 +120,8 @@ public class MapView extends FrameLayout implements LocationListener { private static final float DIMENSION_SIXTEEN_DP = 16f; private static final float DIMENSION_TEN_DP = 10f; + private static final int IMPROVE_THIS_MAP_INDEX = 2; + /** * Every annotation that has been added to the map. */ @@ -425,7 +427,7 @@ public class MapView extends FrameLayout implements LocationListener { LayoutParams attrParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); mAttributionsView.setLayoutParams(attrParams); addView(mAttributionsView); - mAttributionsView.setOnClickListener(new AttributionOnClickListener()); + mAttributionsView.setOnClickListener(new AttributionOnClickListener(this)); // Setup Support For Listener Tracking // MapView's internal listener is setup in onCreate() @@ -2040,6 +2042,12 @@ public class MapView extends FrameLayout implements LocationListener { private static class AttributionOnClickListener implements View.OnClickListener, DialogInterface.OnClickListener { + private MapView mMapView; + + public AttributionOnClickListener(MapView mapView) { + mMapView = mapView; + } + // Called when someone presses the attribution icon @Override public void onClick(View v) { @@ -2051,13 +2059,17 @@ public class MapView extends FrameLayout implements LocationListener { builder.show(); } - // Called when someone selects an attribution + // Called when someone selects an attribution, 'Improve this map' adds location data to the url @Override public void onClick(DialogInterface dialog, int which) { - Context context = ((Dialog)dialog).getContext(); - String[]links = context.getResources().getStringArray(R.array.attribution_links); + Context context = ((Dialog) dialog).getContext(); + String url = context.getResources().getStringArray(R.array.attribution_links)[which]; + if (which == IMPROVE_THIS_MAP_INDEX) { + LatLng latLng = mMapView.getCenterCoordinate(); + url = String.format(url, latLng.getLongitude(), latLng.getLatitude(), (int) mMapView.getZoomLevel()); + } Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(links[which])); + intent.setData(Uri.parse(url)); context.startActivity(intent); } } diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/values/arrays.xml b/android/java/MapboxGLAndroidSDK/src/main/res/values/arrays.xml index 3e937722c..8a8e204b7 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/values/arrays.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/values/arrays.xml @@ -8,6 +8,6 @@ https://www.mapbox.com/about/maps/ http://www.openstreetmap.org/about/ - https://www.mapbox.com/map-feedback + https://www.mapbox.com/map-feedback/#/%1$f/%2$f/%3$d \ No newline at end of file