Skip to content

Commit

Permalink
Merge pull request #567 from ryankask/fit-to-elements-fix
Browse files Browse the repository at this point in the history
Don't fit to elements if no positions added
  • Loading branch information
Spike Brehm committed Sep 12, 2016
2 parents 0e22228 + 05ab993 commit d854912
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,20 +462,27 @@ public void animateToCoordinate(LatLng coordinate, int duration) {

public void fitToElements(boolean animated) {
LatLngBounds.Builder builder = new LatLngBounds.Builder();

boolean addedPosition = false;

for (AirMapFeature feature : features) {
if (feature instanceof AirMapMarker) {
Marker marker = (Marker) feature.getFeature();
builder.include(marker.getPosition());
addedPosition = true;
}
// TODO(lmr): may want to include shapes / etc.
}
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
if (animated) {
startMonitoringRegion();
map.animateCamera(cu);
} else {
map.moveCamera(cu);

if (addedPosition) {
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
if (animated) {
startMonitoringRegion();
map.animateCamera(cu);
} else {
map.moveCamera(cu);
}
}
}

Expand Down

0 comments on commit d854912

Please sign in to comment.