Skip to content

Commit

Permalink
fix(example): ensure zoom buttons zoom by a full zoom level only (#1861)
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurtanuki committed Mar 28, 2024
1 parent c2806fd commit 8d106d2
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions example/lib/plugins/zoombuttons_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class FlutterMapZoomButtons extends StatelessWidget {
final IconData zoomInIcon;
final IconData zoomOutIcon;

static const _fitBoundsPadding = EdgeInsets.all(12);

const FlutterMapZoomButtons({
super.key,
this.minZoom = 1,
Expand Down Expand Up @@ -52,12 +50,8 @@ class FlutterMapZoomButtons extends StatelessWidget {
mini: mini,
backgroundColor: zoomInColor ?? theme.primaryColor,
onPressed: () {
final paddedMapCamera = CameraFit.bounds(
bounds: camera.visibleBounds,
padding: _fitBoundsPadding,
).fit(camera);
final zoom = min(paddedMapCamera.zoom + 1, maxZoom);
controller.move(paddedMapCamera.center, zoom);
final zoom = min(camera.zoom + 1, maxZoom);
controller.move(camera.center, zoom);
},
child: Icon(zoomInIcon,
color: zoomInColorIcon ?? theme.iconTheme.color),
Expand All @@ -70,15 +64,8 @@ class FlutterMapZoomButtons extends StatelessWidget {
mini: mini,
backgroundColor: zoomOutColor ?? theme.primaryColor,
onPressed: () {
final paddedMapCamera = CameraFit.bounds(
bounds: camera.visibleBounds,
padding: _fitBoundsPadding,
).fit(camera);
var zoom = paddedMapCamera.zoom - 1;
if (zoom < minZoom) {
zoom = minZoom;
}
controller.move(paddedMapCamera.center, zoom);
final zoom = max(camera.zoom - 1, minZoom);
controller.move(camera.center, zoom);
},
child: Icon(zoomOutIcon,
color: zoomOutColorIcon ?? theme.iconTheme.color),
Expand Down

0 comments on commit 8d106d2

Please sign in to comment.