From 231eb30e78aec256d2ef1143fb9eba8da358040b Mon Sep 17 00:00:00 2001 From: Jv Date: Mon, 17 Aug 2020 14:52:35 +0300 Subject: [PATCH 1/8] Added Id Parameter on the addMarkerRaw Method so a custom id can be used instead of just the position Added patterns, width and color parameter on addDirection method, to customize the polyline --- lib/src/core/google_map.state.dart | 5 +++++ lib/src/core/map_operations.dart | 5 +++++ lib/src/mobile/google_map.state.dart | 14 ++++++++++---- lib/src/web/google_map.state.dart | 10 +++++++--- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/src/core/google_map.state.dart b/lib/src/core/google_map.state.dart index 1aa2606..dc70160 100644 --- a/lib/src/core/google_map.state.dart +++ b/lib/src/core/google_map.state.dart @@ -11,6 +11,7 @@ import 'package:google_directions_api/google_directions_api.dart' import 'map_items.dart'; import 'google_map.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart' show PatternItem; class GoogleMapState extends GoogleMapStateBase { @override @@ -59,6 +60,9 @@ class GoogleMapState extends GoogleMapStateBase { String endLabel, String endIcon, String endInfo, + List patterns, + int width, + Color color, }) => throw UnimplementedError(); @@ -66,6 +70,7 @@ class GoogleMapState extends GoogleMapStateBase { void addMarkerRaw( GeoCoord position, { String label, + String id, String icon, String info, String infoSnippet, diff --git a/lib/src/core/map_operations.dart b/lib/src/core/map_operations.dart index 4b4c713..c200d4f 100644 --- a/lib/src/core/map_operations.dart +++ b/lib/src/core/map_operations.dart @@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart' show ValueChanged; import 'package:google_directions_api/google_directions_api.dart' show GeoCoord, GeoCoordBounds; +import 'package:google_maps_flutter/google_maps_flutter.dart' show PatternItem; import 'map_items.dart'; /// Interface of setting up map operations including: @@ -121,6 +122,7 @@ abstract class MapMarkers { /// If marker with same [position] have been already added, addition of a new marker will be ignored. void addMarkerRaw( GeoCoord position, { + String id, String label, String icon, String info, @@ -161,6 +163,9 @@ abstract class MapDirections { String endLabel, String endIcon, String endInfo, + List patterns, + int width, + Color color, }); /// Removes a direction from the map by given [origin] and [destination] coordinates. diff --git a/lib/src/mobile/google_map.state.dart b/lib/src/mobile/google_map.state.dart index 40afc56..96973b4 100644 --- a/lib/src/mobile/google_map.state.dart +++ b/lib/src/mobile/google_map.state.dart @@ -14,6 +14,7 @@ import 'utils.dart'; import '../core/utils.dart' as utils; import '../core/google_map.dart' as gmap; import '../core/map_items.dart' as items; +import 'package:google_maps_flutter/google_maps_flutter.dart' show PatternItem; class GoogleMapState extends gmap.GoogleMapStateBase { final directionsService = DirectionsService(); @@ -160,6 +161,7 @@ class GoogleMapState extends gmap.GoogleMapStateBase { void addMarkerRaw( GeoCoord position, { String label, + String id, String icon, String info, String infoSnippet, @@ -178,9 +180,9 @@ class GoogleMapState extends gmap.GoogleMapStateBase { return true; }()); - final key = position.toString(); + final key = id ?? position.toString(); + if (id == null && _markers.containsKey(key)) return; - if (_markers.containsKey(key)) return; final markerId = MarkerId(key); final marker = Marker( @@ -248,6 +250,9 @@ class GoogleMapState extends gmap.GoogleMapStateBase { String endLabel, String endIcon, String endInfo, + List patterns, + int width, + Color color = const Color(0xcc2196F3), }) { assert(() { if (origin == null) { @@ -328,10 +333,11 @@ class GoogleMapState extends gmap.GoogleMapStateBase { points: response?.routes?.firstOrNull?.overviewPath ?.mapList((_) => _.toLatLng()) ?? [startLatLng?.toLatLng(), endLatLng?.toLatLng()], - color: const Color(0xcc2196F3), + color: color, startCap: Cap.roundCap, endCap: Cap.roundCap, - width: 8, + width: width, + patterns: patterns ?? [], ); _setState(() => _polylines[key] = polyline); diff --git a/lib/src/web/google_map.state.dart b/lib/src/web/google_map.state.dart index acef791..6e05456 100644 --- a/lib/src/web/google_map.state.dart +++ b/lib/src/web/google_map.state.dart @@ -19,6 +19,7 @@ import 'utils.dart'; import '../core/google_map.dart'; import '../core/utils.dart' as utils; import '../core/map_items.dart' as items; +import 'package:google_maps_flutter/google_maps_flutter.dart' show PatternItem; class GoogleMapState extends GoogleMapStateBase { final htmlId = Uuid().v1(); @@ -133,6 +134,7 @@ class GoogleMapState extends GoogleMapStateBase { void addMarkerRaw( GeoCoord position, { String label, + String id, String icon, String info, String infoSnippet, @@ -151,9 +153,8 @@ class GoogleMapState extends GoogleMapStateBase { return true; }()); - final key = position.toString(); - - if (_markers.containsKey(key)) return; + final key = id ?? position.toString(); + if (id == null && _markers.containsKey(key)) return; final marker = Marker() ..map = _map @@ -274,6 +275,9 @@ class GoogleMapState extends GoogleMapStateBase { String endLabel, String endIcon, String endInfo, + List patterns, + int width, + Color color, }) { assert(() { if (origin == null) { From 9f390f784a5e27279f068327bb9b61c2c62a0b10 Mon Sep 17 00:00:00 2001 From: Jv Date: Mon, 17 Aug 2020 15:13:16 +0300 Subject: [PATCH 2/8] Added event for map movement, added current zoom and bounds attribute --- lib/src/core/google_map.dart | 4 ++++ lib/src/core/google_map.state.dart | 5 +++++ lib/src/core/map_operations.dart | 6 ++++++ lib/src/mobile/google_map.state.dart | 7 +++++++ lib/src/web/google_map.state.dart | 20 +++++++++++++++++--- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/src/core/google_map.dart b/lib/src/core/google_map.dart index 4820849..d07e163 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; diff --git a/lib/src/core/google_map.state.dart b/lib/src/core/google_map.state.dart index dc70160..35f0e61 100644 --- a/lib/src/core/google_map.state.dart +++ b/lib/src/core/google_map.state.dart @@ -14,6 +14,7 @@ import 'google_map.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart' show PatternItem; class GoogleMapState extends GoogleMapStateBase { + @override void moveCameraBounds( GeoCoordBounds newBounds, { @@ -43,6 +44,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 c200d4f..7d36fdc 100644 --- a/lib/src/core/map_operations.dart +++ b/lib/src/core/map_operations.dart @@ -70,6 +70,12 @@ abstract class MapOperations /// 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 96973b4..7b2e602 100644 --- a/lib/src/mobile/google_map.state.dart +++ b/lib/src/mobile/google_map.state.dart @@ -142,6 +142,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, { @@ -600,6 +605,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 6e05456..00f0d6d 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'; @@ -64,13 +65,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 @@ -117,6 +118,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, { @@ -650,6 +655,7 @@ class GoogleMapState extends GoogleMapStateBase { _createMapOptions(); if (_map == null) { + // ignore: undefined_prefixed_name ui.platformViewRegistry.registerViewFactory(htmlId, (int viewId) { final elem = DivElement() ..id = htmlId @@ -659,6 +665,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( @@ -690,7 +705,6 @@ class GoogleMapState extends GoogleMapStateBase { _infos.clear(); _markers.clear(); _polygons.clear(); - _circles.clear(); _infoState.clear(); _directions.clear(); _subscriptions.clear(); From 89e606bc5a02d2a7ff488fe8f1e5db8fa0a604aa Mon Sep 17 00:00:00 2001 From: Jv Date: Mon, 17 Aug 2020 15:28:32 +0300 Subject: [PATCH 3/8] Added event for when map is idle --- lib/src/core/google_map.dart | 2 ++ lib/src/mobile/google_map.state.dart | 11 +++++------ lib/src/web/google_map.state.dart | 4 +++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/src/core/google_map.dart b/lib/src/core/google_map.dart index d07e163..2aa15ac 100644 --- a/lib/src/core/google_map.dart +++ b/lib/src/core/google_map.dart @@ -28,6 +28,7 @@ class GoogleMap extends StatefulWidget { this.markers, this.onTap, this.onLongPress, + this.onMapIdle, this.onMapMove, this.interactive = true, this.initialZoom = _zoom, @@ -87,6 +88,7 @@ class GoogleMap extends StatefulWidget { /// For `web` this will be called when `right mouse clicked`. final ValueChanged onLongPress; + final void Function() onMapIdle; final ValueChanged onMapMove; /// Set of mobile map preferences. diff --git a/lib/src/mobile/google_map.state.dart b/lib/src/mobile/google_map.state.dart index 7b2e602..b37a2f6 100644 --- a/lib/src/mobile/google_map.state.dart +++ b/lib/src/mobile/google_map.state.dart @@ -142,10 +142,10 @@ class GoogleMapState extends gmap.GoogleMapStateBase { FutureOr get center async => (await _controller?.getVisibleRegion())?.toGeoCoordBounds()?.center; - FutureOr get zoom async => - (await _controller?.getZoomLevel()); + FutureOr get zoom async => (await _controller?.getZoomLevel()); - FutureOr get bounds async => (await _controller?.getVisibleRegion()).toGeoCoordBounds(); + FutureOr get bounds async => + (await _controller?.getVisibleRegion()).toGeoCoordBounds(); @override void changeMapStyle( @@ -188,7 +188,6 @@ class GoogleMapState extends gmap.GoogleMapStateBase { final key = id ?? position.toString(); if (id == null && _markers.containsKey(key)) return; - final markerId = MarkerId(key); final marker = Marker( markerId: markerId, @@ -605,8 +604,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), + onCameraMove: (position) => widget.onMapMove?.call(position), + onCameraIdle: () => widget.onMapIdle?.call(), 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 00f0d6d..04c6a62 100644 --- a/lib/src/web/google_map.state.dart +++ b/lib/src/web/google_map.state.dart @@ -664,7 +664,9 @@ class GoogleMapState extends GoogleMapStateBase { ..style.border = 'none'; _map = GMap(elem, _mapOptions); - + _subscriptions.add(_map.onIdle.listen((event) { + widget.onMapIdle?.call(); + })); _subscriptions.add(_map.onCenterChanged.listen( (event) { gmaps.CameraPosition pos = gmaps.CameraPosition( From 87b299c2c53669f8d13989a5af6bc496512a7245 Mon Sep 17 00:00:00 2001 From: Jv Date: Mon, 17 Aug 2020 15:30:11 +0300 Subject: [PATCH 4/8] Updated version and dependencies --- pubspec.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5014564..2febd04 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: flutter_google_maps -version: 4.0.0 +version: 4.1.0 homepage: https://github.com/marchdev-tk/flutter_google_maps description: A Flutter plugin for integrating Google Maps in iOS, Android and Web applications. It is a wrapper of google_maps_flutter for Mobile and google_maps for Web. @@ -11,18 +11,18 @@ dependencies: sdk: flutter google_polyline_algorithm: ^2.0.0 - google_maps_flutter: ^0.5.28+1 + google_maps_flutter: ^0.5.30 google_directions_api: ^0.5.0 - google_maps: ^3.4.3 - http: ^0.12.1 - flinq: ^1.1.0 - uuid: ^2.1.0 + google_maps: ^3.4.4 + http: ^0.12.2 + flinq: ^1.1.1 + uuid: ^2.2.0 dev_dependencies: flutter_test: sdk: flutter - pedantic: ^1.8.0 + pedantic: ^1.9.2 flutter: uses-material-design: true From 32ccce0afdfadee98dfa0b4fcff504b8cf00d889 Mon Sep 17 00:00:00 2001 From: Jv Date: Wed, 17 Mar 2021 10:48:41 +0300 Subject: [PATCH 5/8] dependency update --- example/lib/main.dart | 5 +++-- example/web/index.html | 3 ++- pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 6c5efb8..1737fdb 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -112,7 +112,7 @@ class _MyHomePageState extends State { const SizedBox(width: 16), FloatingActionButton( child: Icon(Icons.pin_drop), - onPressed: () { + onPressed: () async{ GoogleMap.of(_key).addMarkerRaw( GeoCoord(33.875513, -117.550257), info: 'test info', @@ -132,8 +132,9 @@ class _MyHomePageState extends State { ); }, ); + GoogleMap.of(_key).addMarkerRaw( - GeoCoord(33.775513, -117.450257), + await GoogleMap.of(_key).center, icon: 'assets/images/map-marker-warehouse.png', info: contentString, ); diff --git a/example/web/index.html b/example/web/index.html index 338f68c..f95443d 100644 --- a/example/web/index.html +++ b/example/web/index.html @@ -5,7 +5,8 @@ flutter_google_maps_example - + + diff --git a/pubspec.yaml b/pubspec.yaml index 2febd04..06b5d7c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: google_maps: ^3.4.4 http: ^0.12.2 flinq: ^1.1.1 - uuid: ^2.2.0 + uuid: ^3.0.1 dev_dependencies: flutter_test: From bd3f8f0b2549106c32b8aaab9f312d999711864e Mon Sep 17 00:00:00 2001 From: Jv Date: Wed, 17 Mar 2021 10:50:45 +0300 Subject: [PATCH 6/8] dependency update --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 06b5d7c..0bf0ef1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: google_maps_flutter: ^0.5.30 google_directions_api: ^0.5.0 google_maps: ^3.4.4 - http: ^0.12.2 + http: ^0.13.0 flinq: ^1.1.1 uuid: ^3.0.1 From 9f6c39aeacdb82382ec34aa0b53b886f69f2b450 Mon Sep 17 00:00:00 2001 From: Jv Date: Wed, 17 Mar 2021 10:55:49 +0300 Subject: [PATCH 7/8] dependency update --- pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 0bf0ef1..5cabf06 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,8 @@ dependencies: google_maps: ^3.4.4 http: ^0.13.0 flinq: ^1.1.1 - uuid: ^3.0.1 + uuid: ^2.2.0 + dev_dependencies: flutter_test: From 2edfd12308b0877a07bc76b9eabe746966c794e8 Mon Sep 17 00:00:00 2001 From: Jv Date: Wed, 17 Mar 2021 10:57:11 +0300 Subject: [PATCH 8/8] dependency update --- pubspec.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5cabf06..2febd04 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,11 +14,10 @@ dependencies: google_maps_flutter: ^0.5.30 google_directions_api: ^0.5.0 google_maps: ^3.4.4 - http: ^0.13.0 + http: ^0.12.2 flinq: ^1.1.1 uuid: ^2.2.0 - dev_dependencies: flutter_test: sdk: flutter