Skip to content

Commit

Permalink
mapbox#1856 - Cleaning up annotations selection option and centering …
Browse files Browse the repository at this point in the history
…map on annotation display area
  • Loading branch information
bleege committed Aug 7, 2015
1 parent eee4774 commit 99e9d9b
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.mapbox.mapboxgl.geometry.LatLng;
import com.mapbox.mapboxgl.views.MapView;
import io.fabric.sdk.android.Fabric;
import org.json.JSONException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -64,8 +64,8 @@ public class MainActivity extends AppCompatActivity {
// Used for GPS
private MenuItem mGpsMenuItem;

// Used for markers
private boolean mIsMarkersOn = false;
// Used for Annotations
private boolean mIsAnnotationsOn = false;

private Marker marker;

Expand Down Expand Up @@ -279,7 +279,7 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {

case R.id.action_markers:
// Toggle markers
toggleMarkers(!mIsMarkersOn);
toggleAnnotations(!mIsAnnotationsOn);
break;

case R.id.action_compass:
Expand Down Expand Up @@ -341,21 +341,23 @@ private void toggleGps(boolean enableGps) {
}

/**
* Enable / Disable markers.
* Enable / Disable Annotations.
*
* @param enableMarkers
* @param enableAnnotations True to display, False to hide
*/
private void toggleMarkers(boolean enableMarkers) {
if (enableMarkers) {
if (!mIsMarkersOn) {
mIsMarkersOn = true;
private void toggleAnnotations(boolean enableAnnotations) {
if (enableAnnotations) {
if (!mIsAnnotationsOn) {
mIsAnnotationsOn = true;
addMarkers();
addPolyline();
addPolygon();
mapView.setZoomLevel(7);
mapView.setCenterCoordinate(new LatLng(38.11727, -122.22839));
}
} else {
if (mIsMarkersOn) {
mIsMarkersOn = false;
if (mIsAnnotationsOn) {
mIsAnnotationsOn = false;
removeAnnotations();
}
}
Expand Down Expand Up @@ -386,9 +388,8 @@ private void addPolyline() {
.add(latLngs)
.width(2)
.color(Color.RED));
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (Exception e) {
Log.e(TAG, "Error adding Polyline: "+ e);
e.printStackTrace();
}
}
Expand All @@ -405,9 +406,8 @@ private void addPolygon() {
.strokeColor(Color.MAGENTA)
.fillColor(Color.BLUE));
Polygon polygon = map.addPolygons(opts).get(0);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (Exception e) {
Log.e(TAG, "Error adding Polygon: "+ e);
e.printStackTrace();
}
}
Expand Down

0 comments on commit 99e9d9b

Please sign in to comment.