diff --git a/lib/src/core/google_map.dart b/lib/src/core/google_map.dart index 4820849..4dda8d2 100644 --- a/lib/src/core/google_map.dart +++ b/lib/src/core/google_map.dart @@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart'; import 'package:google_directions_api/google_directions_api.dart' show GeoCoord, DirectionsService; +import 'package:google_maps_flutter/google_maps_flutter.dart' as gmap; import 'map_items.dart'; import 'map_operations.dart'; @@ -27,6 +28,7 @@ class GoogleMap extends StatefulWidget { this.markers, this.onTap, this.onLongPress, + this.onMapMove, this.interactive = true, this.initialZoom = _zoom, this.mapType = MapType.roadmap, @@ -85,6 +87,8 @@ class GoogleMap extends StatefulWidget { /// For `web` this will be called when `right mouse clicked`. final ValueChanged onLongPress; + final ValueChanged onMapMove; + /// Set of mobile map preferences. final MobileMapPreferences mobilePreferences; @@ -117,4 +121,4 @@ abstract class GoogleMapStateBase extends State icon.endsWith('/marker_a.png') || icon.endsWith('/marker_b.png') ? 'packages/flutter_google_maps/' : ''; -} +} \ No newline at end of file diff --git a/lib/src/core/google_map.state.dart b/lib/src/core/google_map.state.dart index 4c5f8ae..ae50ffe 100644 --- a/lib/src/core/google_map.state.dart +++ b/lib/src/core/google_map.state.dart @@ -13,6 +13,7 @@ import 'map_items.dart'; import 'google_map.dart'; class GoogleMapState extends GoogleMapStateBase { + @override void moveCameraBounds( GeoCoordBounds newBounds, { @@ -42,6 +43,10 @@ class GoogleMapState extends GoogleMapStateBase { @override FutureOr get center => throw UnimplementedError(); + FutureOr get zoom => throw UnimplementedError(); + + FutureOr get bounds => throw UnimplementedError(); + @override void changeMapStyle( String mapStyle, { diff --git a/lib/src/core/map_operations.dart b/lib/src/core/map_operations.dart index b995009..6691181 100644 --- a/lib/src/core/map_operations.dart +++ b/lib/src/core/map_operations.dart @@ -68,6 +68,12 @@ abstract class MapOperations implements MapMarkers, MapDirections, MapPolygons { /// Gets center coordinates of the map. FutureOr get center; + + /// Gets zoom coordinates of the map. + FutureOr get zoom; + + /// Gets zoom coordinates of the map. + FutureOr get bounds; /// Sets the styling of the base map. /// diff --git a/lib/src/mobile/google_map.state.dart b/lib/src/mobile/google_map.state.dart index 3abb3ab..591db91 100644 --- a/lib/src/mobile/google_map.state.dart +++ b/lib/src/mobile/google_map.state.dart @@ -140,6 +140,11 @@ class GoogleMapState extends gmap.GoogleMapStateBase { FutureOr get center async => (await _controller?.getVisibleRegion())?.toGeoCoordBounds()?.center; + FutureOr get zoom async => + (await _controller?.getZoomLevel()); + + FutureOr get bounds async => (await _controller?.getVisibleRegion()).toGeoCoordBounds(); + @override void changeMapStyle( String mapStyle, { @@ -504,6 +509,8 @@ class GoogleMapState extends gmap.GoogleMapStateBase { onTap: (coords) => widget.onTap?.call(coords?.toGeoCoord()), onLongPress: (coords) => widget.onLongPress?.call(coords?.toGeoCoord()), + onCameraMove: (position) => + widget.onMapMove?.call(position), onMapCreated: (GoogleMapController controller) { _controller = controller; _controller.setMapStyle(widget.mapStyle); diff --git a/lib/src/web/google_map.state.dart b/lib/src/web/google_map.state.dart index 367ceab..400726e 100644 --- a/lib/src/web/google_map.state.dart +++ b/lib/src/web/google_map.state.dart @@ -8,6 +8,7 @@ import 'dart:ui' as ui; import 'package:flutter/widgets.dart'; import 'package:flutter/scheduler.dart' show SchedulerBinding; +import 'package:google_maps_flutter/google_maps_flutter.dart' as gmaps; import 'package:uuid/uuid.dart'; import 'package:flinq/flinq.dart'; @@ -62,13 +63,13 @@ class GoogleMapState extends GoogleMapStateBase { _map.center = newBounds.center.toLatLng(); - final zoom = _map.zoom; + // final zoom = _map.zoom; if (animated == true) { _map.panToBounds(newBounds.toLatLngBounds()); } else { _map.fitBounds(newBounds.toLatLngBounds()); } - _map.zoom = zoom; + // _map.zoom = zoom; } @override @@ -115,6 +116,10 @@ class GoogleMapState extends GoogleMapStateBase { @override FutureOr get center => _map.center?.toGeoCoord(); + FutureOr get zoom => _map.zoom.toDouble(); + + FutureOr get bounds => _map.bounds.toGeoCoordBounds(); + @override void changeMapStyle( String mapStyle, { @@ -553,6 +558,15 @@ class GoogleMapState extends GoogleMapStateBase { _map = GMap(elem, _mapOptions); + _subscriptions.add(_map.onCenterChanged.listen( + (event) { + gmaps.CameraPosition pos = gmaps.CameraPosition( + target: gmaps.LatLng( _map.center.lat, _map.center.lng), + zoom: _map.zoom.toDouble(), + tilt: _map.tilt, + ); + widget.onMapMove?.call(pos); + })); _subscriptions.add(_map.onClick.listen( (event) => widget.onTap?.call(event?.latLng?.toGeoCoord()))); _subscriptions.add(_map.onRightclick.listen(