diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index 1bd301926..0060fcce1 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,3 +1,13 @@ +## 0.4.0 + +* Add support for `mapTypeControlEnabled`, `fullscreenControlEnabled`, `streetViewControlEnabled`, `webCameraControlEnabled`, `webCameraControlPosition`, `webGestureHandling`, and `fortyFiveDegreeImageryEnabled`. +* Fix `consumeTapEvents` for circles, polygons, and polylines. +* Fix initial map objects being added to the map twice. +* Fix `onMapCreated` never being called when a map tile request stalls or fails. +* Fix map events being dropped when the reported coordinates are integers. +* Fix cluster managers passed to the initial `GoogleMap` being ignored. +* Fix `Cluster.markerIds` holding internal ids instead of the markers' `MarkerId`s. + ## 0.3.0 * Update `webview_flutter_lwe` to ^0.6.0. diff --git a/packages/google_maps_flutter/README.md b/packages/google_maps_flutter/README.md index bc360b151..3b9f9c238 100644 --- a/packages/google_maps_flutter/README.md +++ b/packages/google_maps_flutter/README.md @@ -21,7 +21,7 @@ This package is not an _endorsed_ implementation of `google_maps_flutter`. There ```yaml dependencies: google_maps_flutter: ^2.18.0 - google_maps_flutter_tizen: ^0.3.0 + google_maps_flutter_tizen: ^0.4.0 ``` For detailed usage, see https://pub.dev/packages/google_maps_flutter#sample-usage. diff --git a/packages/google_maps_flutter/lib/src/convert.dart b/packages/google_maps_flutter/lib/src/convert.dart index a90cc004a..0ce394c00 100644 --- a/packages/google_maps_flutter/lib/src/convert.dart +++ b/packages/google_maps_flutter/lib/src/convert.dart @@ -19,7 +19,8 @@ Map _mapTypeToMapTypeId = { // Builds the raw map options map from a [MapConfiguration]. // // This mirrors the platform interface's `jsonForMapConfiguration` helper -// (which is not exported), plus [MapConfiguration.colorScheme]. +// (which is not exported), plus [MapConfiguration.colorScheme] and the web +// control options. // // Intentionally omitted: // * `cloudMapId` — deprecated alias for `mapId`, which is already serialized. @@ -53,6 +54,18 @@ Map _mapOptionsFromConfiguration(MapConfiguration config) { if (config.mapId != null) 'mapId': config.mapId, if (config.style != null) 'style': config.style, if (config.colorScheme != null) 'colorScheme': config.colorScheme!.index, + if (config.webGestureHandling != null) 'webGestureHandling': config.webGestureHandling!.name, + if (config.fortyFiveDegreeImageryEnabled != null) + 'fortyFiveDegreeImageryEnabled': config.fortyFiveDegreeImageryEnabled, + if (config.webCameraControlEnabled != null) + 'webCameraControlEnabled': config.webCameraControlEnabled, + if (config.webCameraControlPosition != null) + 'webCameraControlPosition': config.webCameraControlPosition!.name, + if (config.mapTypeControlEnabled != null) 'mapTypeControlEnabled': config.mapTypeControlEnabled, + if (config.fullscreenControlEnabled != null) + 'fullscreenControlEnabled': config.fullscreenControlEnabled, + if (config.streetViewControlEnabled != null) + 'streetViewControlEnabled': config.streetViewControlEnabled, }; } @@ -89,9 +102,11 @@ String? _getCameraBounds(dynamic option) { // web buildingsEnabled seems to not have an equivalent in web padding seems to // behave differently in web than mobile. You can't move UI elements in web. String _rawOptionsToString(Map rawOptions) { - // These don't have any rawOptions entry, but they seem to be off in the - // native maps. - var options = 'mapTypeControl: false, fullscreenControl: false, streetViewControl: false'; + // These are off by default in the native maps. + var options = + 'mapTypeControl: ${rawOptions['mapTypeControlEnabled'] ?? false}' + ', fullscreenControl: ${rawOptions['fullscreenControlEnabled'] ?? false}' + ', streetViewControl: ${rawOptions['streetViewControlEnabled'] ?? false}'; if (_mapTypeToMapTypeId.containsKey(rawOptions['mapType'])) { options += ", mapTypeId: '${_mapTypeToMapTypeId[rawOptions['mapType']]}'"; @@ -115,13 +130,31 @@ String _rawOptionsToString(Map rawOptions) { options += ', zoomControl: ${rawOptions['zoomControlsEnabled']}'; } + if (rawOptions['webCameraControlEnabled'] != null) { + options += ', cameraControl: ${rawOptions['webCameraControlEnabled']}'; + } + + if (rawOptions['webCameraControlPosition'] != null) { + final String position = (rawOptions['webCameraControlPosition'] as String) + .replaceAllMapped(RegExp('[A-Z]'), (Match m) => '_${m[0]}') + .toUpperCase(); + options += ', cameraControlOptions: { position: google.maps.ControlPosition.$position }'; + } + + if (rawOptions['fortyFiveDegreeImageryEnabled'] != null) { + options += ', rotateControl: ${rawOptions['fortyFiveDegreeImageryEnabled']}'; + } + if (rawOptions['style'] != null && (rawOptions['style'] as String).isNotEmpty) { options += ', styles: ${rawOptions['style']}'; } else { options += ', styles: null'; } - if (rawOptions['scrollGesturesEnabled'] == false || rawOptions['zoomGesturesEnabled'] == false) { + if (rawOptions['webGestureHandling'] != null) { + options += ", gestureHandling: '${rawOptions['webGestureHandling']}'"; + } else if (rawOptions['scrollGesturesEnabled'] == false || + rawOptions['zoomGesturesEnabled'] == false) { options += ", gestureHandling: 'none'"; } else { options += ", gestureHandling: 'auto'"; @@ -223,14 +256,14 @@ LatLngBounds _convertToBounds(String value) { final dynamic bound = json.decode(value); if (bound is Map) { assert( - bound['south'] is double && - bound['west'] is double && - bound['north'] is double && - bound['east'] is double, + bound['south'] is num && + bound['west'] is num && + bound['north'] is num && + bound['east'] is num, ); return LatLngBounds( - southwest: LatLng(bound['south'] as double, bound['west'] as double), - northeast: LatLng(bound['north'] as double, bound['east'] as double), + southwest: LatLng((bound['south'] as num).toDouble(), (bound['west'] as num).toDouble()), + northeast: LatLng((bound['north'] as num).toDouble(), (bound['east'] as num).toDouble()), ); } } catch (e) { @@ -373,7 +406,8 @@ util.GPolylineOptions _polylineOptionsFromPolyline(Polyline polyline) { ..strokeOpacity = _getCssOpacity(polyline.color) ..visible = polyline.visible ..zIndex = polyline.zIndex - ..geodesic = polyline.geodesic; + ..geodesic = polyline.geodesic + ..clickable = polyline.consumeTapEvents; } util.GPolygonOptions _polygonOptionsFromPolygon(Polygon polygon) { @@ -405,7 +439,8 @@ util.GPolygonOptions _polygonOptionsFromPolygon(Polygon polygon) { ..fillOpacity = _getCssOpacity(polygon.fillColor) ..visible = polygon.visible ..zIndex = polygon.zIndex - ..geodesic = polygon.geodesic; + ..geodesic = polygon.geodesic + ..clickable = polygon.consumeTapEvents; } /// Calculates the direction of a given Polygon @@ -440,7 +475,8 @@ util.GCircleOptions _circleOptionsFromCircle(Circle circle) { ..center = LatLng(circle.center.latitude, circle.center.longitude) ..radius = circle.radius ..visible = circle.visible - ..zIndex = circle.zIndex; + ..zIndex = circle.zIndex + ..clickable = circle.consumeTapEvents; } util.GGroundOverlayOptions? _groundOverlayOptionsFromGroundOverlay(GroundOverlay groundOverlay) { diff --git a/packages/google_maps_flutter/lib/src/google_maps_controller.dart b/packages/google_maps_flutter/lib/src/google_maps_controller.dart index 0fabc520a..62db01b00 100644 --- a/packages/google_maps_flutter/lib/src/google_maps_controller.dart +++ b/packages/google_maps_flutter/lib/src/google_maps_controller.dart @@ -37,6 +37,7 @@ class GoogleMapsController { _clusterManagersController = ClusterManagersController( stream: _streamController, bridge: _bridge, + markerIdForId: (int id) => _markersController?._idToMarkerId[id], ); _markersController = MarkersController( stream: _streamController, @@ -139,9 +140,9 @@ class GoogleMapsController { case MapsJsEventType.boundsChanged: await _onBoundsChanged(); case MapsJsEventType.idle: - _onIdle(); + await _onIdle(); case MapsJsEventType.tilesLoaded: - _onTilesloaded(); + _onMapReady(); case MapsJsEventType.click: _onClick(event.message!); case MapsJsEventType.longPress: @@ -215,14 +216,26 @@ class GoogleMapsController { } } - void _onIdle() { + Future _onIdle() async { _mapIsMoving = false; _streamController.add(CameraIdleEvent(_mapId)); + // NOTE: `tilesloaded` never fires if a tile request stalls or fails. + // See https://github.com/flutter/flutter/issues/193452. + if (!_isFirst && await _isMapLaidOut()) { + _onMapReady(); + } + } + + Future _isMapLaidOut() async { + final Object value = await _bridge.runJavaScriptReturningResult( + 'map.getDiv().offsetWidth > 0 && map.getDiv().offsetHeight > 0', + ); + return value.toString() == 'true'; } - void _onTilesloaded() { + void _onMapReady() { try { - if (_isFirst) { + if (_isFirst || _streamController.isClosed) { return; } _streamController.add(MapReadyEvent(_mapId)); @@ -237,7 +250,10 @@ class GoogleMapsController { final dynamic event = json.decode(message); if (event is Map) { assert(event['latLng'] != null); - final position = LatLng(event['latLng']['lat'] as double, event['latLng']['lng'] as double); + final position = LatLng( + (event['latLng']['lat'] as num).toDouble(), + (event['latLng']['lng'] as num).toDouble(), + ); _streamController.add(MapTapEvent(_mapId, position)); } } catch (e) { @@ -250,7 +266,10 @@ class GoogleMapsController { final dynamic event = json.decode(message); if (event is Map) { assert(event['latLng'] != null); - final position = LatLng(event['latLng']['lat'] as double, event['latLng']['lng'] as double); + final position = LatLng( + (event['latLng']['lat'] as num).toDouble(), + (event['latLng']['lng'] as num).toDouble(), + ); _streamController.add(MapLongPressEvent(_mapId, position)); } } catch (e) { @@ -302,8 +321,8 @@ class GoogleMapsController { final MarkerController? marker = _markersController!._markerIdToController[markerId]; final position = LatLng( - result['event']['latLng']['lat'] as double, - result['event']['latLng']['lng'] as double, + (result['event']['latLng']['lat'] as num).toDouble(), + (result['event']['latLng']['lng'] as num).toDouble(), ); if (marker?.dragStartEvent != null) { @@ -326,8 +345,8 @@ class GoogleMapsController { final MarkerController? marker = _markersController!._markerIdToController[markerId]; final position = LatLng( - result['event']['latLng']['lat'] as double, - result['event']['latLng']['lng'] as double, + (result['event']['latLng']['lat'] as num).toDouble(), + (result['event']['latLng']['lng'] as num).toDouble(), ); if (marker?.dragEvent != null) { @@ -350,8 +369,8 @@ class GoogleMapsController { final MarkerController? marker = _markersController!._markerIdToController[markerId]; final position = LatLng( - result['event']['latLng']['lat'] as double, - result['event']['latLng']['lng'] as double, + (result['event']['latLng']['lat'] as num).toDouble(), + (result['event']['latLng']['lng'] as num).toDouble(), ); if (marker?.dragEndEvent != null) { @@ -433,7 +452,13 @@ class GoogleMapsController { /// /// Failure to call this method would result in not rendering at all, /// and most of the public methods on this class no-op'ing. - Future init() async { + /// + /// Later calls return the same future. + Future init() => _initFuture ??= _init(); + + Future? _initFuture; + + Future _init() async { if (_webview == null && !_streamController.isClosed) { _getWebview(); if (!await _bridge.load()) { @@ -445,6 +470,8 @@ class GoogleMapsController { await _createMap(); } await _attachGeometryControllers(); + _initClustering(_clusterManagers); + _renderInitialGeometry( markers: _markers, circles: _circles, @@ -453,8 +480,6 @@ class GoogleMapsController { groundOverlays: _groundOverlays, ); - _initClustering(_clusterManagers); - await _setTrafficLayer(_isTrafficLayerEnabled(_rawMapOptions)); } @@ -588,7 +613,9 @@ class GoogleMapsController { Future _getZoom() async { try { - return (await _callMethod('getZoom', []) as num) + 0.0; + // NOTE: Returns '' if called while the webview is being torn down. + final Object zoom = await _callMethod('getZoom', []); + return zoom is num ? zoom.toDouble() : 0.0; } catch (e) { debugPrint('JavaScript Error: $e'); return 0.0; diff --git a/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart b/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart index 7b439cf8f..46b8a35d4 100644 --- a/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart +++ b/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart @@ -53,6 +53,12 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { _map(mapId).updateRawOptions(optionsUpdate); } + /// Updates the configuration of a given `mapId`. + @override + Future updateMapConfiguration(MapConfiguration configuration, {required int mapId}) async { + _map(mapId).updateRawOptions(_mapOptionsFromConfiguration(configuration)); + } + /// Applies the passed in `markerUpdates` to the `mapId`. @override Future updateMarkers(MarkerUpdates markerUpdates, {required int mapId}) async { @@ -289,6 +295,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { polygons: mapObjects.polygons, polylines: mapObjects.polylines, circles: mapObjects.circles, + clusterManagers: mapObjects.clusterManagers, groundOverlays: mapObjects.groundOverlays, gestureRecognizers: widgetConfiguration.gestureRecognizers, mapOptions: _mapOptionsFromConfiguration(mapConfiguration), @@ -330,6 +337,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { Set polygons = const {}, Set polylines = const {}, Set circles = const {}, + Set clusterManagers = const {}, Set groundOverlays = const {}, Set>? gestureRecognizers = const >{}, @@ -350,6 +358,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { polygons: polygons, polylines: polylines, circles: circles, + clusterManagers: clusterManagers, groundOverlays: groundOverlays, mapOptions: mapOptions, )..init(); // Initialize the controller diff --git a/packages/google_maps_flutter/lib/src/marker_clustering.dart b/packages/google_maps_flutter/lib/src/marker_clustering.dart index 2df839e34..b1087cb99 100644 --- a/packages/google_maps_flutter/lib/src/marker_clustering.dart +++ b/packages/google_maps_flutter/lib/src/marker_clustering.dart @@ -18,8 +18,10 @@ class ClusterManagersController extends GeometryController { ClusterManagersController({ required StreamController> stream, required GoogleMapsJsBridge bridge, + required MarkerId? Function(int id) markerIdForId, }) : _streamController = stream, _bridge = bridge, + _markerIdForId = markerIdForId, _idToClusterManagerId = {}, _clusterManagerIdToMarkerClusterer = {}; @@ -28,6 +30,8 @@ class ClusterManagersController extends GeometryController { final GoogleMapsJsBridge _bridge; + final MarkerId? Function(int id) _markerIdForId; + // A cache of [MarkerClusterer]s indexed by their [ClusterManagerId]. final Map _clusterManagerIdToMarkerClusterer; final Map _idToClusterManagerId; @@ -144,23 +148,24 @@ class ClusterManagersController extends GeometryController { Map markerClustererCluster, ) { final position = LatLng( - (markerClustererCluster['position'] as dynamic)['lat'] as double, - (markerClustererCluster['position'] as dynamic)['lng'] as double, + ((markerClustererCluster['position'] as dynamic)['lat'] as num).toDouble(), + ((markerClustererCluster['position'] as dynamic)['lng'] as num).toDouble(), ); final bounds = LatLngBounds( southwest: LatLng( - (markerClustererCluster['bounds'] as dynamic)['south'] as double, - (markerClustererCluster['bounds'] as dynamic)['west'] as double, + ((markerClustererCluster['bounds'] as dynamic)['south'] as num).toDouble(), + ((markerClustererCluster['bounds'] as dynamic)['west'] as num).toDouble(), ), northeast: LatLng( - (markerClustererCluster['bounds'] as dynamic)['north'] as double, - (markerClustererCluster['bounds'] as dynamic)['east'] as double, + ((markerClustererCluster['bounds'] as dynamic)['north'] as num).toDouble(), + ((markerClustererCluster['bounds'] as dynamic)['east'] as num).toDouble(), ), ); final List markerIds = (markerClustererCluster['markers']! as List) - .map((dynamic markerId) => MarkerId((markerId as int).toString())) + .map((dynamic id) => _markerIdForId(id as int)) + .nonNulls .toList(); return Cluster(clusterManagerId, markerIds, position: position, bounds: bounds); diff --git a/packages/google_maps_flutter/lib/src/util.dart b/packages/google_maps_flutter/lib/src/util.dart index 2158c92c1..f08d63056 100644 --- a/packages/google_maps_flutter/lib/src/util.dart +++ b/packages/google_maps_flutter/lib/src/util.dart @@ -397,6 +397,9 @@ class GPolylineOptions { /// The zIndex compared to other polys. num? zIndex; + /// Whether click events are handled. + bool? clickable; + @override String toString() { final paths = StringBuffer(); @@ -407,7 +410,8 @@ class GPolylineOptions { } return '{geodesic:$geodesic, path:[$paths], strokeColor:${jsonEncode(strokeColor)},' - ' strokeOpacity:$strokeOpacity, map: map, strokeWeight:$strokeWeight, visible:$visible, zIndex:$zIndex}'; + ' strokeOpacity:$strokeOpacity, map: map, strokeWeight:$strokeWeight, visible:$visible, zIndex:$zIndex,' + ' clickable:$clickable}'; } } @@ -492,6 +496,9 @@ class GPolygonOptions { /// The zIndex compared to other polys. num? zIndex; + /// Whether click events are handled. + bool? clickable; + @override String toString() { final str = StringBuffer(); @@ -507,7 +514,8 @@ class GPolygonOptions { return '{fillColor:${jsonEncode(fillColor)}, fillOpacity:$fillOpacity, geodesic:$geodesic, paths:[$str],' ' strokeColor:${jsonEncode(strokeColor)}, strokeOpacity:$strokeOpacity, map: map,' - ' strokeWeight:$strokeWeight, visible:$visible, zIndex:$zIndex}'; + ' strokeWeight:$strokeWeight, visible:$visible, zIndex:$zIndex,' + ' clickable:$clickable}'; } } @@ -597,11 +605,15 @@ class GCircleOptions { /// The zIndex compared to other polys. num? zIndex; + /// Whether click events are handled. + bool? clickable; + @override String toString() { return '{center: new google.maps.LatLng(${center?.latitude}, ${center?.longitude}), fillColor:${jsonEncode(fillColor)},' ' fillOpacity:$fillOpacity, radius:$radius, strokeColor:${jsonEncode(strokeColor)}, strokeOpacity:$strokeOpacity,' - ' map: map, strokeWeight:$strokeWeight, visible:$visible, zIndex:$zIndex}'; + ' map: map, strokeWeight:$strokeWeight, visible:$visible, zIndex:$zIndex,' + ' clickable:$clickable}'; } } diff --git a/packages/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/pubspec.yaml index 06cbba114..c39cc9d04 100644 --- a/packages/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_tizen description: Tizen implementation of the google_maps_flutter plugin. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/main/packages/google_maps_flutter -version: 0.3.0 +version: 0.4.0 environment: sdk: ^3.10.0