Skip to content

Commit

Permalink
GeoShapeActivity: Fix zooming to a polygon that has only one vertex.
Browse files Browse the repository at this point in the history
  • Loading branch information
zestyping committed Oct 3, 2018
1 parent 4b55e6c commit 40d3b8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ public GoogleMap getGoogleMap() {
if (points != null) {
int count = 0;
LatLngBounds.Builder builder = new LatLngBounds.Builder();
LatLng latLng = null;
for (MapPoint point : points) {
builder.include(toLatLng(point));
latLng = toLatLng(point);
builder.include(latLng);
count++;
}
if (count > 0) {
if (count == 1) {
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));
} else if (count > 1) {
final LatLngBounds bounds = expandBounds(builder.build(), 1 / scaleFactor);
new Handler().postDelayed(() -> {
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ public MapView getMapView() {
geoPoints.add(toGeoPoint(point));
count++;
}
if (count > 0) {
map.getController().setZoom(4);
map.invalidate();
if (count == 1) {
map.getController().setCenter(geoPoints.get(0));
map.getController().setZoom(16);
} else if (count > 1) {
map.zoomToBoundingBox(BoundingBox.fromGeoPoints(
geoPoints).increaseByScale((float) (1 / scaleFactor)), true);
}
Expand Down

0 comments on commit 40d3b8f

Please sign in to comment.