Skip to content

Commit

Permalink
Split padding values in CameraUpdate.newLatLngBounds() (flutter-mapbo…
Browse files Browse the repository at this point in the history
…x-gl#382)

* Split padding values in CameraUpdate.newLatLngBounds()

* Remove old unused code

Co-authored-by: Tobrun <[email protected]>
  • Loading branch information
m0nac0 and tobrun authored Sep 8, 2020
1 parent fb573d4 commit 1835210
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.9.0,
* Breaking change: CameraUpdate.newLatLngBounds() now supports setting different padding values for left, top, right, bottom with default of 0 for all. Implementations using the old approach with only one padding value for all edges have to be updated. [#382](https://github.com/tobrun/flutter-mapbox-gl/pull/382)

## 0.8.0, August 22, 2020
- implementation of feature querying [#177](https://github.com/tobrun/flutter-mapbox-gl/pull/177)
- Batch create/delete of symbols [#279](https://github.com/tobrun/flutter-mapbox-gl/pull/279)
Expand All @@ -7,7 +10,6 @@
- Set dependencies from git [#319](https://github.com/tobrun/flutter-mapbox-gl/pull/319)
- Add line#getGeometry and symbol#getGeometry [#281](https://github.com/tobrun/flutter-mapbox-gl/pull/281)


## 0.7.0, June 6, 2020
* Introduction of mapbox_gl_platform_interface library
* Introduction of mapbox_gl_web library
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/com/mapbox/mapboxgl/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ static CameraUpdate toCameraUpdate(Object o, MapboxMap mapboxMap, float density)
case "newLatLng":
return CameraUpdateFactory.newLatLng(toLatLng(data.get(1)));
case "newLatLngBounds":
return CameraUpdateFactory.newLatLngBounds(
toLatLngBounds(data.get(1)), toPixels(data.get(2), density));
return CameraUpdateFactory.newLatLngBounds(toLatLngBounds(data.get(1)), toPixels(data.get(2), density),
toPixels(data.get(3), density), toPixels(data.get(4), density), toPixels(data.get(5), density));
case "newLatLngZoom":
return CameraUpdateFactory.newLatLngZoom(toLatLng(data.get(1)), toFloat(data.get(2)));
case "scrollBy":
Expand Down
4 changes: 3 additions & 1 deletion example/lib/animate_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class AnimateCameraState extends State<AnimateCamera> {
southwest: const LatLng(-38.483935, 113.248673),
northeast: const LatLng(-8.982446, 153.823821),
),
10.0,
left: 10,
top: 5,
bottom: 25,
),
);
},
Expand Down
4 changes: 3 additions & 1 deletion example/lib/move_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class MoveCameraState extends State<MoveCamera> {
southwest: const LatLng(-38.483935, 113.248673),
northeast: const LatLng(-8.982446, 153.823821),
),
10.0,
left: 10,
top: 5,
bottom: 25,
),
);
},
Expand Down
7 changes: 5 additions & 2 deletions ios/Classes/Convert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ class Convert {
return camera
case "newLatLngBounds":
guard let bounds = cameraUpdate[1] as? [[Double]] else { return nil }
guard let padding = cameraUpdate[2] as? CGFloat else { return nil }
return mapView.cameraThatFitsCoordinateBounds(MGLCoordinateBounds.fromArray(bounds), edgePadding: UIEdgeInsets.init(top: padding, left: padding, bottom: padding, right: padding))
guard let paddingLeft = cameraUpdate[2] as? CGFloat else { return nil }
guard let paddingTop = cameraUpdate[3] as? CGFloat else { return nil }
guard let paddingRight = cameraUpdate[4] as? CGFloat else { return nil }
guard let paddingBottom = cameraUpdate[5] as? CGFloat else { return nil }
return mapView.cameraThatFitsCoordinateBounds(MGLCoordinateBounds.fromArray(bounds), edgePadding: UIEdgeInsets.init(top: paddingTop, left: paddingLeft, bottom: paddingBottom, right: paddingRight))
case "newLatLngZoom":
guard let coordinate = cameraUpdate[1] as? [Double] else { return nil }
guard let zoom = cameraUpdate[2] as? Double else { return nil }
Expand Down
14 changes: 10 additions & 4 deletions mapbox_gl_platform_interface/lib/src/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,21 @@ class CameraUpdate {
return CameraUpdate._(<dynamic>['newLatLng', latLng.toJson()]);
}


/// Returns a camera update that transforms the camera so that the specified
/// geographical bounding box is centered in the map view at the greatest
/// possible zoom level. A non-zero [padding] insets the bounding box from the
/// map view's edges. The camera's new tilt and bearing will both be 0.0.
static CameraUpdate newLatLngBounds(LatLngBounds bounds, double padding) {
/// possible zoom level. A non-zero [left], [top], [right] and [bottom] padding
/// insets the bounding box from the map view's edges.
/// The camera's new tilt and bearing will both be 0.0.
static CameraUpdate newLatLngBounds(LatLngBounds bounds,
{double left = 0, double top = 0, double right = 0, double bottom = 0}) {
return CameraUpdate._(<dynamic>[
'newLatLngBounds',
bounds.toList(),
padding,
left,
top,
right,
bottom,
]);
}

Expand Down
13 changes: 8 additions & 5 deletions mapbox_gl_web/lib/src/convert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ class Convert {
);
case 'newLatLngBounds':
final bounds = json[1];
final padding = json[2];
final left = json[2];
final top = json[3];
final right = json[4];
final bottom = json[5];
final camera = mapboxMap.cameraForBounds(
LngLatBounds(
LngLat(bounds[0][1], bounds[0][0]),
LngLat(bounds[1][1], bounds[1][0]),
),
{
'padding': {
'top': padding,
'bottom': padding,
'left': padding,
'right': padding
'top': top,
'bottom': bottom,
'left': left,
'right': right,
}
});
return camera;
Expand Down

0 comments on commit 1835210

Please sign in to comment.