diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index 975455232491..7f47917268eb 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.27 + +* Migrate the core plugin to use `google_maps_flutter_platform_interface` APIs. + ## 0.5.26+4 * Android: Fix map view crash when "exit app" while using `FragmentActivity`. diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart index 5f3889f7b2f1..a17b30ca6226 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart @@ -13,22 +13,36 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -part 'src/bitmap.dart'; -part 'src/callbacks.dart'; -part 'src/camera.dart'; -part 'src/cap.dart'; -part 'src/circle.dart'; -part 'src/circle_updates.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_platform_interface/src/method_channel/method_channel_google_maps_flutter.dart'; + +export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart' + show + ArgumentCallbacks, + ArgumentCallback, + BitmapDescriptor, + CameraPosition, + CameraPositionCallback, + CameraTargetBounds, + CameraUpdate, + Cap, + Circle, + CircleId, + InfoWindow, + JointType, + LatLng, + LatLngBounds, + MapStyleException, + MapType, + Marker, + MarkerId, + MinMaxZoomPreference, + PatternItem, + Polygon, + PolygonId, + Polyline, + PolylineId, + ScreenCoordinate; + part 'src/controller.dart'; part 'src/google_map.dart'; -part 'src/joint_type.dart'; -part 'src/location.dart'; -part 'src/marker.dart'; -part 'src/marker_updates.dart'; -part 'src/pattern_item.dart'; -part 'src/polygon.dart'; -part 'src/polygon_updates.dart'; -part 'src/polyline.dart'; -part 'src/polyline_updates.dart'; -part 'src/screen_coordinate.dart'; -part 'src/ui.dart'; diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/bitmap.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/bitmap.dart deleted file mode 100644 index 7cf5b2e25b7e..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/bitmap.dart +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Defines a bitmap image. For a marker, this class can be used to set the -/// image of the marker icon. For a ground overlay, it can be used to set the -/// image to place on the surface of the earth. -class BitmapDescriptor { - const BitmapDescriptor._(this._json); - - /// Convenience hue value representing red. - static const double hueRed = 0.0; - - /// Convenience hue value representing orange. - static const double hueOrange = 30.0; - - /// Convenience hue value representing yellow. - static const double hueYellow = 60.0; - - /// Convenience hue value representing green. - static const double hueGreen = 120.0; - - /// Convenience hue value representing cyan. - static const double hueCyan = 180.0; - - /// Convenience hue value representing azure. - static const double hueAzure = 210.0; - - /// Convenience hue value representing blue. - static const double hueBlue = 240.0; - - /// Convenience hue value representing violet. - static const double hueViolet = 270.0; - - /// Convenience hue value representing magenta. - static const double hueMagenta = 300.0; - - /// Convenience hue value representing rose. - static const double hueRose = 330.0; - - /// Creates a BitmapDescriptor that refers to the default marker image. - static const BitmapDescriptor defaultMarker = - BitmapDescriptor._(['defaultMarker']); - - /// Creates a BitmapDescriptor that refers to a colorization of the default - /// marker image. For convenience, there is a predefined set of hue values. - /// See e.g. [hueYellow]. - static BitmapDescriptor defaultMarkerWithHue(double hue) { - assert(0.0 <= hue && hue < 360.0); - return BitmapDescriptor._(['defaultMarker', hue]); - } - - /// Creates a BitmapDescriptor using the name of a bitmap image in the assets - /// directory. - /// - /// Use [fromAssetImage]. This method does not respect the screen dpi when - /// picking an asset image. - @Deprecated("Use fromAssetImage instead") - static BitmapDescriptor fromAsset(String assetName, {String package}) { - if (package == null) { - return BitmapDescriptor._(['fromAsset', assetName]); - } else { - return BitmapDescriptor._(['fromAsset', assetName, package]); - } - } - - /// Creates a [BitmapDescriptor] from an asset image. - /// - /// Asset images in flutter are stored per: - /// https://flutter.dev/docs/development/ui/assets-and-images#declaring-resolution-aware-image-assets - /// This method takes into consideration various asset resolutions - /// and scales the images to the right resolution depending on the dpi. - /// Set `mipmaps` to false to load the exact dpi version of the image, `mipmap` is true by default. - static Future fromAssetImage( - ImageConfiguration configuration, - String assetName, { - AssetBundle bundle, - String package, - bool mipmaps = true, - }) async { - if (!mipmaps && configuration.devicePixelRatio != null) { - return BitmapDescriptor._([ - 'fromAssetImage', - assetName, - configuration.devicePixelRatio, - ]); - } - final AssetImage assetImage = - AssetImage(assetName, package: package, bundle: bundle); - final AssetBundleImageKey assetBundleImageKey = - await assetImage.obtainKey(configuration); - return BitmapDescriptor._([ - 'fromAssetImage', - assetBundleImageKey.name, - assetBundleImageKey.scale, - ]); - } - - /// Creates a BitmapDescriptor using an array of bytes that must be encoded - /// as PNG. - static BitmapDescriptor fromBytes(Uint8List byteData) { - return BitmapDescriptor._(['fromBytes', byteData]); - } - - final dynamic _json; - - /// Convert the object to a Json format. - /// Used for testing only. - @visibleForTesting - dynamic toJson() => _json; - - dynamic _toJson() => _json; -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/callbacks.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/callbacks.dart deleted file mode 100644 index 284c7134cbfb..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/callbacks.dart +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Callback function taking a single argument. -typedef void ArgumentCallback(T argument); - -/// Mutable collection of [ArgumentCallback] instances, itself an [ArgumentCallback]. -/// -/// Additions and removals happening during a single [call] invocation do not -/// change who gets a callback until the next such invocation. -/// -/// Optimized for the singleton case. -class ArgumentCallbacks { - final List> _callbacks = >[]; - - /// Callback method. Invokes the corresponding method on each callback - /// in this collection. - /// - /// The list of callbacks being invoked is computed at the start of the - /// method and is unaffected by any changes subsequently made to this - /// collection. - void call(T argument) { - final int length = _callbacks.length; - if (length == 1) { - _callbacks[0].call(argument); - } else if (0 < length) { - for (ArgumentCallback callback - in List>.from(_callbacks)) { - callback(argument); - } - } - } - - /// Adds a callback to this collection. - void add(ArgumentCallback callback) { - assert(callback != null); - _callbacks.add(callback); - } - - /// Removes a callback from this collection. - /// - /// Does nothing, if the callback was not present. - void remove(ArgumentCallback callback) { - _callbacks.remove(callback); - } - - /// Whether this collection is empty. - bool get isEmpty => _callbacks.isEmpty; - - /// Whether this collection is non-empty. - bool get isNotEmpty => _callbacks.isNotEmpty; -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/camera.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/camera.dart deleted file mode 100644 index 043d0f8c9d78..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/camera.dart +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// The position of the map "camera", the view point from which the world is shown in the map view. -/// -/// Aggregates the camera's [target] geographical location, its [zoom] level, -/// [tilt] angle, and [bearing]. -class CameraPosition { - /// Creates a immutable representation of the [GoogleMap] camera. - /// - /// [AssertionError] is thrown if [bearing], [target], [tilt], or [zoom] are - /// null. - const CameraPosition({ - this.bearing = 0.0, - @required this.target, - this.tilt = 0.0, - this.zoom = 0.0, - }) : assert(bearing != null), - assert(target != null), - assert(tilt != null), - assert(zoom != null); - - /// The camera's bearing in degrees, measured clockwise from north. - /// - /// A bearing of 0.0, the default, means the camera points north. - /// A bearing of 90.0 means the camera points east. - final double bearing; - - /// The geographical location that the camera is pointing at. - final LatLng target; - - /// The angle, in degrees, of the camera angle from the nadir. - /// - /// A tilt of 0.0, the default and minimum supported value, means the camera - /// is directly facing the Earth. - /// - /// The maximum tilt value depends on the current zoom level. Values beyond - /// the supported range are allowed, but on applying them to a map they will - /// be silently clamped to the supported range. - final double tilt; - - /// The zoom level of the camera. - /// - /// A zoom of 0.0, the default, means the screen width of the world is 256. - /// Adding 1.0 to the zoom level doubles the screen width of the map. So at - /// zoom level 3.0, the screen width of the world is 2³x256=2048. - /// - /// Larger zoom levels thus means the camera is placed closer to the surface - /// of the Earth, revealing more detail in a narrower geographical region. - /// - /// The supported zoom level range depends on the map data and device. Values - /// beyond the supported range are allowed, but on applying them to a map they - /// will be silently clamped to the supported range. - final double zoom; - - /// Serializes [CameraPosition]. - /// - /// Mainly for internal use when calling [CameraUpdate.newCameraPosition]. - dynamic toMap() => { - 'bearing': bearing, - 'target': target._toJson(), - 'tilt': tilt, - 'zoom': zoom, - }; - - /// Deserializes [CameraPosition] from a map. - /// - /// Mainly for internal use. - static CameraPosition fromMap(dynamic json) { - if (json == null) { - return null; - } - return CameraPosition( - bearing: json['bearing'], - target: LatLng._fromJson(json['target']), - tilt: json['tilt'], - zoom: json['zoom'], - ); - } - - @override - bool operator ==(dynamic other) { - if (identical(this, other)) return true; - if (runtimeType != other.runtimeType) return false; - final CameraPosition typedOther = other; - return bearing == typedOther.bearing && - target == typedOther.target && - tilt == typedOther.tilt && - zoom == typedOther.zoom; - } - - @override - int get hashCode => hashValues(bearing, target, tilt, zoom); - - @override - String toString() => - 'CameraPosition(bearing: $bearing, target: $target, tilt: $tilt, zoom: $zoom)'; -} - -/// Defines a camera move, supporting absolute moves as well as moves relative -/// the current position. -class CameraUpdate { - CameraUpdate._(this._json); - - /// Returns a camera update that moves the camera to the specified position. - static CameraUpdate newCameraPosition(CameraPosition cameraPosition) { - return CameraUpdate._( - ['newCameraPosition', cameraPosition.toMap()], - ); - } - - /// Returns a camera update that moves the camera target to the specified - /// geographical location. - static CameraUpdate newLatLng(LatLng latLng) { - return CameraUpdate._(['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) { - return CameraUpdate._([ - 'newLatLngBounds', - bounds._toList(), - padding, - ]); - } - - /// Returns a camera update that moves the camera target to the specified - /// geographical location and zoom level. - static CameraUpdate newLatLngZoom(LatLng latLng, double zoom) { - return CameraUpdate._( - ['newLatLngZoom', latLng._toJson(), zoom], - ); - } - - /// Returns a camera update that moves the camera target the specified screen - /// distance. - /// - /// For a camera with bearing 0.0 (pointing north), scrolling by 50,75 moves - /// the camera's target to a geographical location that is 50 to the east and - /// 75 to the south of the current location, measured in screen coordinates. - static CameraUpdate scrollBy(double dx, double dy) { - return CameraUpdate._( - ['scrollBy', dx, dy], - ); - } - - /// Returns a camera update that modifies the camera zoom level by the - /// specified amount. The optional [focus] is a screen point whose underlying - /// geographical location should be invariant, if possible, by the movement. - static CameraUpdate zoomBy(double amount, [Offset focus]) { - if (focus == null) { - return CameraUpdate._(['zoomBy', amount]); - } else { - return CameraUpdate._([ - 'zoomBy', - amount, - [focus.dx, focus.dy], - ]); - } - } - - /// Returns a camera update that zooms the camera in, bringing the camera - /// closer to the surface of the Earth. - /// - /// Equivalent to the result of calling `zoomBy(1.0)`. - static CameraUpdate zoomIn() { - return CameraUpdate._(['zoomIn']); - } - - /// Returns a camera update that zooms the camera out, bringing the camera - /// further away from the surface of the Earth. - /// - /// Equivalent to the result of calling `zoomBy(-1.0)`. - static CameraUpdate zoomOut() { - return CameraUpdate._(['zoomOut']); - } - - /// Returns a camera update that sets the camera zoom level. - static CameraUpdate zoomTo(double zoom) { - return CameraUpdate._(['zoomTo', zoom]); - } - - final dynamic _json; - - dynamic _toJson() => _json; -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/cap.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/cap.dart deleted file mode 100644 index 1a6be1f3f528..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/cap.dart +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Cap that can be applied at the start or end vertex of a [Polyline]. -@immutable -class Cap { - const Cap._(this._json); - - /// Cap that is squared off exactly at the start or end vertex of a [Polyline] - /// with solid stroke pattern, equivalent to having no additional cap beyond - /// the start or end vertex. - /// - /// This is the default cap type at start and end vertices of Polylines with - /// solid stroke pattern. - static const Cap buttCap = Cap._(['buttCap']); - - /// Cap that is a semicircle with radius equal to half the stroke width, - /// centered at the start or end vertex of a [Polyline] with solid stroke - /// pattern. - static const Cap roundCap = Cap._(['roundCap']); - - /// Cap that is squared off after extending half the stroke width beyond the - /// start or end vertex of a [Polyline] with solid stroke pattern. - static const Cap squareCap = Cap._(['squareCap']); - - /// Constructs a new CustomCap with a bitmap overlay centered at the start or - /// end vertex of a [Polyline], orientated according to the direction of the line's - /// first or last edge and scaled with respect to the line's stroke width. - /// - /// CustomCap can be applied to [Polyline] with any stroke pattern. - /// - /// [bitmapDescriptor] must not be null. - /// - /// [refWidth] is the reference stroke width (in pixels) - the stroke width for which - /// the cap bitmap at its native dimension is designed. Must be positive. Default value - /// is 10 pixels. - static Cap customCapFromBitmap( - BitmapDescriptor bitmapDescriptor, { - double refWidth = 10, - }) { - assert(bitmapDescriptor != null); - assert(refWidth > 0.0); - return Cap._(['customCap', bitmapDescriptor._toJson(), refWidth]); - } - - final dynamic _json; - - dynamic _toJson() => _json; -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/circle.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/circle.dart deleted file mode 100644 index 3edfc88ed4e0..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/circle.dart +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Uniquely identifies a [Circle] among [GoogleMap] circles. -/// -/// This does not have to be globally unique, only unique among the list. -@immutable -class CircleId { - /// Creates an immutable identifier for a [Circle]. - CircleId(this.value) : assert(value != null); - - /// value of the [CircleId]. - final String value; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final CircleId typedOther = other; - return value == typedOther.value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() { - return 'CircleId{value: $value}'; - } -} - -/// Draws a circle on the map. -@immutable -class Circle { - /// Creates an immutable representation of a [Circle] to draw on [GoogleMap]. - const Circle({ - @required this.circleId, - this.consumeTapEvents = false, - this.fillColor = Colors.transparent, - this.center = const LatLng(0.0, 0.0), - this.radius = 0, - this.strokeColor = Colors.black, - this.strokeWidth = 10, - this.visible = true, - this.zIndex = 0, - this.onTap, - }); - - /// Uniquely identifies a [Circle]. - final CircleId circleId; - - /// True if the [Circle] consumes tap events. - /// - /// If this is false, [onTap] callback will not be triggered. - final bool consumeTapEvents; - - /// Fill color in ARGB format, the same format used by Color. The default value is transparent (0x00000000). - final Color fillColor; - - /// Geographical location of the circle center. - final LatLng center; - - /// Radius of the circle in meters; must be positive. The default value is 0. - final double radius; - - /// Fill color in ARGB format, the same format used by Color. The default value is black (0xff000000). - final Color strokeColor; - - /// The width of the circle's outline in screen points. - /// - /// The width is constant and independent of the camera's zoom level. - /// The default value is 10. - /// Setting strokeWidth to 0 results in no stroke. - final int strokeWidth; - - /// True if the circle is visible. - final bool visible; - - /// The z-index of the circle, used to determine relative drawing order of - /// map overlays. - /// - /// Overlays are drawn in order of z-index, so that lower values means drawn - /// earlier, and thus appearing to be closer to the surface of the Earth. - final int zIndex; - - /// Callbacks to receive tap events for circle placed on this map. - final VoidCallback onTap; - - /// Creates a new [Circle] object whose values are the same as this instance, - /// unless overwritten by the specified parameters. - Circle copyWith({ - bool consumeTapEventsParam, - Color fillColorParam, - LatLng centerParam, - double radiusParam, - Color strokeColorParam, - int strokeWidthParam, - bool visibleParam, - int zIndexParam, - VoidCallback onTapParam, - }) { - return Circle( - circleId: circleId, - consumeTapEvents: consumeTapEventsParam ?? consumeTapEvents, - fillColor: fillColorParam ?? fillColor, - center: centerParam ?? center, - radius: radiusParam ?? radius, - strokeColor: strokeColorParam ?? strokeColor, - strokeWidth: strokeWidthParam ?? strokeWidth, - visible: visibleParam ?? visible, - zIndex: zIndexParam ?? zIndex, - onTap: onTapParam ?? onTap, - ); - } - - /// Creates a new [Circle] object whose values are the same as this instance. - Circle clone() => copyWith(); - - dynamic _toJson() { - final Map json = {}; - - void addIfPresent(String fieldName, dynamic value) { - if (value != null) { - json[fieldName] = value; - } - } - - addIfPresent('circleId', circleId.value); - addIfPresent('consumeTapEvents', consumeTapEvents); - addIfPresent('fillColor', fillColor.value); - addIfPresent('center', center._toJson()); - addIfPresent('radius', radius); - addIfPresent('strokeColor', strokeColor.value); - addIfPresent('strokeWidth', strokeWidth); - addIfPresent('visible', visible); - addIfPresent('zIndex', zIndex); - - return json; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Circle typedOther = other; - return circleId == typedOther.circleId && - consumeTapEvents == typedOther.consumeTapEvents && - fillColor == typedOther.fillColor && - center == typedOther.center && - radius == typedOther.radius && - strokeColor == typedOther.strokeColor && - strokeWidth == typedOther.strokeWidth && - visible == typedOther.visible && - zIndex == typedOther.zIndex; - } - - @override - int get hashCode => circleId.hashCode; -} - -Map _keyByCircleId(Iterable circles) { - if (circles == null) { - return {}; - } - return Map.fromEntries(circles.map((Circle circle) => - MapEntry(circle.circleId, circle.clone()))); -} - -List> _serializeCircleSet(Set circles) { - if (circles == null) { - return null; - } - return circles.map>((Circle p) => p._toJson()).toList(); -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/circle_updates.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/circle_updates.dart deleted file mode 100644 index c977c4182c98..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/circle_updates.dart +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// [Circle] update events to be applied to the [GoogleMap]. -/// -/// Used in [GoogleMapController] when the map is updated. -class _CircleUpdates { - /// Computes [_CircleUpdates] given previous and current [Circle]s. - _CircleUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousCircles = _keyByCircleId(previous); - final Map currentCircles = _keyByCircleId(current); - - final Set prevCircleIds = previousCircles.keys.toSet(); - final Set currentCircleIds = currentCircles.keys.toSet(); - - Circle idToCurrentCircle(CircleId id) { - return currentCircles[id]; - } - - final Set _circleIdsToRemove = - prevCircleIds.difference(currentCircleIds); - - final Set _circlesToAdd = currentCircleIds - .difference(prevCircleIds) - .map(idToCurrentCircle) - .toSet(); - - /// Returns `true` if [current] is not equals to previous one with the - /// same id. - bool hasChanged(Circle current) { - final Circle previous = previousCircles[current.circleId]; - return current != previous; - } - - final Set _circlesToChange = currentCircleIds - .intersection(prevCircleIds) - .map(idToCurrentCircle) - .where(hasChanged) - .toSet(); - - circlesToAdd = _circlesToAdd; - circleIdsToRemove = _circleIdsToRemove; - circlesToChange = _circlesToChange; - } - - Set circlesToAdd; - Set circleIdsToRemove; - Set circlesToChange; - - Map _toMap() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull('circlesToAdd', _serializeCircleSet(circlesToAdd)); - addIfNonNull('circlesToChange', _serializeCircleSet(circlesToChange)); - addIfNonNull('circleIdsToRemove', - circleIdsToRemove.map((CircleId m) => m.value).toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final _CircleUpdates typedOther = other; - return setEquals(circlesToAdd, typedOther.circlesToAdd) && - setEquals(circleIdsToRemove, typedOther.circleIdsToRemove) && - setEquals(circlesToChange, typedOther.circlesToChange); - } - - @override - int get hashCode => - hashValues(circlesToAdd, circleIdsToRemove, circlesToChange); - - @override - String toString() { - return '_CircleUpdates{circlesToAdd: $circlesToAdd, ' - 'circleIdsToRemove: $circleIdsToRemove, ' - 'circlesToChange: $circlesToChange}'; - } -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart index 750bb69393e7..f5ee180ab1fd 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart @@ -4,14 +4,20 @@ part of google_maps_flutter; +final GoogleMapsFlutterPlatform _googleMapsFlutterPlatform = + GoogleMapsFlutterPlatform.instance; + /// Controller for a single GoogleMap instance running on the host platform. class GoogleMapController { + /// The mapId for this controller + final int mapId; + GoogleMapController._( - this.channel, CameraPosition initialCameraPosition, - this._googleMapState, - ) : assert(channel != null) { - channel.setMethodCallHandler(_handleMethodCall); + this._googleMapState, { + @required this.mapId, + }) : assert(_googleMapsFlutterPlatform != null) { + _connectStreams(mapId); } /// Initialize control of a [GoogleMap] with [id]. @@ -24,72 +30,66 @@ class GoogleMapController { _GoogleMapState googleMapState, ) async { assert(id != null); - final MethodChannel channel = - MethodChannel('plugins.flutter.io/google_maps_$id'); - await channel.invokeMethod('map#waitForMap'); + await _googleMapsFlutterPlatform.init(id); return GoogleMapController._( - channel, initialCameraPosition, googleMapState, + mapId: id, ); } /// Used to communicate with the native platform. /// /// Accessible only for testing. + // TODO(dit) https://github.com/flutter/flutter/issues/55504 Remove this getter. @visibleForTesting - final MethodChannel channel; + MethodChannel get channel { + if (_googleMapsFlutterPlatform is MethodChannelGoogleMapsFlutter) { + return (_googleMapsFlutterPlatform as MethodChannelGoogleMapsFlutter) + .channel(mapId); + } + return null; + } final _GoogleMapState _googleMapState; - Future _handleMethodCall(MethodCall call) async { - switch (call.method) { - case 'camera#onMoveStarted': - if (_googleMapState.widget.onCameraMoveStarted != null) { - _googleMapState.widget.onCameraMoveStarted(); - } - break; - case 'camera#onMove': - if (_googleMapState.widget.onCameraMove != null) { - _googleMapState.widget.onCameraMove( - CameraPosition.fromMap(call.arguments['position']), - ); - } - break; - case 'camera#onIdle': - if (_googleMapState.widget.onCameraIdle != null) { - _googleMapState.widget.onCameraIdle(); - } - break; - case 'marker#onTap': - _googleMapState.onMarkerTap(call.arguments['markerId']); - break; - case 'marker#onDragEnd': - _googleMapState.onMarkerDragEnd(call.arguments['markerId'], - LatLng._fromJson(call.arguments['position'])); - break; - case 'infoWindow#onTap': - _googleMapState.onInfoWindowTap(call.arguments['markerId']); - break; - case 'polyline#onTap': - _googleMapState.onPolylineTap(call.arguments['polylineId']); - break; - case 'polygon#onTap': - _googleMapState.onPolygonTap(call.arguments['polygonId']); - break; - case 'circle#onTap': - _googleMapState.onCircleTap(call.arguments['circleId']); - break; - case 'map#onTap': - _googleMapState.onTap(LatLng._fromJson(call.arguments['position'])); - break; - case 'map#onLongPress': - _googleMapState - .onLongPress(LatLng._fromJson(call.arguments['position'])); - break; - default: - throw MissingPluginException(); + void _connectStreams(int mapId) { + if (_googleMapState.widget.onCameraMoveStarted != null) { + _googleMapsFlutterPlatform + .onCameraMoveStarted(mapId: mapId) + .listen((_) => _googleMapState.widget.onCameraMoveStarted()); } + if (_googleMapState.widget.onCameraMove != null) { + _googleMapsFlutterPlatform.onCameraMove(mapId: mapId).listen( + (CameraMoveEvent e) => _googleMapState.widget.onCameraMove(e.value)); + } + if (_googleMapState.widget.onCameraIdle != null) { + _googleMapsFlutterPlatform + .onCameraIdle(mapId: mapId) + .listen((_) => _googleMapState.widget.onCameraIdle()); + } + _googleMapsFlutterPlatform + .onMarkerTap(mapId: mapId) + .listen((MarkerTapEvent e) => _googleMapState.onMarkerTap(e.value)); + _googleMapsFlutterPlatform.onMarkerDragEnd(mapId: mapId).listen( + (MarkerDragEndEvent e) => + _googleMapState.onMarkerDragEnd(e.value, e.position)); + _googleMapsFlutterPlatform.onInfoWindowTap(mapId: mapId).listen( + (InfoWindowTapEvent e) => _googleMapState.onInfoWindowTap(e.value)); + _googleMapsFlutterPlatform + .onPolylineTap(mapId: mapId) + .listen((PolylineTapEvent e) => _googleMapState.onPolylineTap(e.value)); + _googleMapsFlutterPlatform + .onPolygonTap(mapId: mapId) + .listen((PolygonTapEvent e) => _googleMapState.onPolygonTap(e.value)); + _googleMapsFlutterPlatform + .onCircleTap(mapId: mapId) + .listen((CircleTapEvent e) => _googleMapState.onCircleTap(e.value)); + _googleMapsFlutterPlatform + .onTap(mapId: mapId) + .listen((MapTapEvent e) => _googleMapState.onTap(e.position)); + _googleMapsFlutterPlatform.onLongPress(mapId: mapId).listen( + (MapLongPressEvent e) => _googleMapState.onLongPress(e.position)); } /// Updates configuration options of the map user interface. @@ -98,14 +98,10 @@ class GoogleMapController { /// platform side. /// /// The returned [Future] completes after listeners have been notified. - Future _updateMapOptions(Map optionsUpdate) async { + Future _updateMapOptions(Map optionsUpdate) { assert(optionsUpdate != null); - await channel.invokeMethod( - 'map#update', - { - 'options': optionsUpdate, - }, - ); + return _googleMapsFlutterPlatform.updateMapOptions(optionsUpdate, + mapId: mapId); } /// Updates marker configuration. @@ -114,12 +110,10 @@ class GoogleMapController { /// platform side. /// /// The returned [Future] completes after listeners have been notified. - Future _updateMarkers(_MarkerUpdates markerUpdates) async { + Future _updateMarkers(MarkerUpdates markerUpdates) { assert(markerUpdates != null); - await channel.invokeMethod( - 'markers#update', - markerUpdates._toMap(), - ); + return _googleMapsFlutterPlatform.updateMarkers(markerUpdates, + mapId: mapId); } /// Updates polygon configuration. @@ -128,12 +122,10 @@ class GoogleMapController { /// platform side. /// /// The returned [Future] completes after listeners have been notified. - Future _updatePolygons(_PolygonUpdates polygonUpdates) async { + Future _updatePolygons(PolygonUpdates polygonUpdates) { assert(polygonUpdates != null); - await channel.invokeMethod( - 'polygons#update', - polygonUpdates._toMap(), - ); + return _googleMapsFlutterPlatform.updatePolygons(polygonUpdates, + mapId: mapId); } /// Updates polyline configuration. @@ -142,12 +134,10 @@ class GoogleMapController { /// platform side. /// /// The returned [Future] completes after listeners have been notified. - Future _updatePolylines(_PolylineUpdates polylineUpdates) async { + Future _updatePolylines(PolylineUpdates polylineUpdates) { assert(polylineUpdates != null); - await channel.invokeMethod( - 'polylines#update', - polylineUpdates._toMap(), - ); + return _googleMapsFlutterPlatform.updatePolylines(polylineUpdates, + mapId: mapId); } /// Updates circle configuration. @@ -156,32 +146,26 @@ class GoogleMapController { /// platform side. /// /// The returned [Future] completes after listeners have been notified. - Future _updateCircles(_CircleUpdates circleUpdates) async { + Future _updateCircles(CircleUpdates circleUpdates) { assert(circleUpdates != null); - await channel.invokeMethod( - 'circles#update', - circleUpdates._toMap(), - ); + return _googleMapsFlutterPlatform.updateCircles(circleUpdates, + mapId: mapId); } /// Starts an animated change of the map camera position. /// /// The returned [Future] completes after the change has been started on the /// platform side. - Future animateCamera(CameraUpdate cameraUpdate) async { - await channel.invokeMethod('camera#animate', { - 'cameraUpdate': cameraUpdate._toJson(), - }); + Future animateCamera(CameraUpdate cameraUpdate) { + return _googleMapsFlutterPlatform.animateCamera(cameraUpdate, mapId: mapId); } /// Changes the map camera position. /// /// The returned [Future] completes after the change has been made on the /// platform side. - Future moveCamera(CameraUpdate cameraUpdate) async { - await channel.invokeMethod('camera#move', { - 'cameraUpdate': cameraUpdate._toJson(), - }); + Future moveCamera(CameraUpdate cameraUpdate) { + return _googleMapsFlutterPlatform.moveCamera(cameraUpdate, mapId: mapId); } /// Sets the styling of the base map. @@ -197,23 +181,13 @@ class GoogleMapController { /// Also, refer [iOS](https://developers.google.com/maps/documentation/ios-sdk/style-reference) /// and [Android](https://developers.google.com/maps/documentation/android-sdk/style-reference) /// style reference for more information regarding the supported styles. - Future setMapStyle(String mapStyle) async { - final List successAndError = - await channel.invokeMethod>('map#setStyle', mapStyle); - final bool success = successAndError[0]; - if (!success) { - throw MapStyleException(successAndError[1]); - } + Future setMapStyle(String mapStyle) { + return _googleMapsFlutterPlatform.setMapStyle(mapStyle, mapId: mapId); } /// Return [LatLngBounds] defining the region that is visible in a map. - Future getVisibleRegion() async { - final Map latLngBounds = - await channel.invokeMapMethod('map#getVisibleRegion'); - final LatLng southwest = LatLng._fromJson(latLngBounds['southwest']); - final LatLng northeast = LatLng._fromJson(latLngBounds['northeast']); - - return LatLngBounds(northeast: northeast, southwest: southwest); + Future getVisibleRegion() { + return _googleMapsFlutterPlatform.getVisibleRegion(mapId: mapId); } /// Return [ScreenCoordinate] of the [LatLng] in the current map view. @@ -221,20 +195,16 @@ class GoogleMapController { /// A projection is used to translate between on screen location and geographic coordinates. /// Screen location is in screen pixels (not display pixels) with respect to the top left corner /// of the map, not necessarily of the whole screen. - Future getScreenCoordinate(LatLng latLng) async { - final Map point = await channel.invokeMapMethod( - 'map#getScreenCoordinate', latLng._toJson()); - return ScreenCoordinate(x: point['x'], y: point['y']); + Future getScreenCoordinate(LatLng latLng) { + return _googleMapsFlutterPlatform.getScreenCoordinate(latLng, mapId: mapId); } /// Returns [LatLng] corresponding to the [ScreenCoordinate] in the current map view. /// /// Returned [LatLng] corresponds to a screen location. The screen location is specified in screen /// pixels (not display pixels) relative to the top left of the map, not top left of the whole screen. - Future getLatLng(ScreenCoordinate screenCoordinate) async { - final List latLng = await channel.invokeMethod>( - 'map#getLatLng', screenCoordinate._toJson()); - return LatLng(latLng[0], latLng[1]); + Future getLatLng(ScreenCoordinate screenCoordinate) { + return _googleMapsFlutterPlatform.getLatLng(screenCoordinate, mapId: mapId); } /// Programmatically show the Info Window for a [Marker]. @@ -245,10 +215,10 @@ class GoogleMapController { /// * See also: /// * [hideMarkerInfoWindow] to hide the Info Window. /// * [isMarkerInfoWindowShown] to check if the Info Window is showing. - Future showMarkerInfoWindow(MarkerId markerId) async { + Future showMarkerInfoWindow(MarkerId markerId) { assert(markerId != null); - await channel.invokeMethod( - 'markers#showInfoWindow', {'markerId': markerId.value}); + return _googleMapsFlutterPlatform.showMarkerInfoWindow(markerId, + mapId: mapId); } /// Programmatically hide the Info Window for a [Marker]. @@ -259,10 +229,10 @@ class GoogleMapController { /// * See also: /// * [showMarkerInfoWindow] to show the Info Window. /// * [isMarkerInfoWindowShown] to check if the Info Window is showing. - Future hideMarkerInfoWindow(MarkerId markerId) async { + Future hideMarkerInfoWindow(MarkerId markerId) { assert(markerId != null); - await channel.invokeMethod( - 'markers#hideInfoWindow', {'markerId': markerId.value}); + return _googleMapsFlutterPlatform.hideMarkerInfoWindow(markerId, + mapId: mapId); } /// Returns `true` when the [InfoWindow] is showing, `false` otherwise. @@ -273,21 +243,19 @@ class GoogleMapController { /// * See also: /// * [showMarkerInfoWindow] to show the Info Window. /// * [hideMarkerInfoWindow] to hide the Info Window. - Future isMarkerInfoWindowShown(MarkerId markerId) async { + Future isMarkerInfoWindowShown(MarkerId markerId) { assert(markerId != null); - return await channel.invokeMethod('markers#isInfoWindowShown', - {'markerId': markerId.value}); + return _googleMapsFlutterPlatform.isMarkerInfoWindowShown(markerId, + mapId: mapId); } /// Returns the current zoom level of the map - Future getZoomLevel() async { - final double zoomLevel = - await channel.invokeMethod('map#getZoomLevel'); - return zoomLevel; + Future getZoomLevel() { + return _googleMapsFlutterPlatform.getZoomLevel(mapId: mapId); } /// Returns the image bytes of the map - Future takeSnapshot() async { - return await channel.invokeMethod('map#takeSnapshot'); + Future takeSnapshot() { + return _googleMapsFlutterPlatform.takeSnapshot(mapId: mapId); } } diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index f2edde3fc6aa..ecd1a708e724 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -10,14 +10,6 @@ part of google_maps_flutter; /// map is created. typedef void MapCreatedCallback(GoogleMapController controller); -/// Callback that receives updates to the camera position. -/// -/// This callback is triggered when the platform Google Map -/// registers a camera movement. -/// -/// This is used in [GoogleMap.onCameraMove]. -typedef void CameraPositionCallback(CameraPosition position); - /// A widget which displays a map with data obtained from the Google Maps service. class GoogleMap extends StatefulWidget { /// Creates a widget displaying data from Google Maps services. @@ -221,41 +213,26 @@ class _GoogleMapState extends State { final Map creationParams = { 'initialCameraPosition': widget.initialCameraPosition?.toMap(), 'options': _googleMapOptions.toMap(), - 'markersToAdd': _serializeMarkerSet(widget.markers), - 'polygonsToAdd': _serializePolygonSet(widget.polygons), - 'polylinesToAdd': _serializePolylineSet(widget.polylines), - 'circlesToAdd': _serializeCircleSet(widget.circles), + 'markersToAdd': serializeMarkerSet(widget.markers), + 'polygonsToAdd': serializePolygonSet(widget.polygons), + 'polylinesToAdd': serializePolylineSet(widget.polylines), + 'circlesToAdd': serializeCircleSet(widget.circles), }; - if (defaultTargetPlatform == TargetPlatform.android) { - return AndroidView( - viewType: 'plugins.flutter.io/google_maps', - onPlatformViewCreated: onPlatformViewCreated, - gestureRecognizers: widget.gestureRecognizers, - creationParams: creationParams, - creationParamsCodec: const StandardMessageCodec(), - ); - } else if (defaultTargetPlatform == TargetPlatform.iOS) { - return UiKitView( - viewType: 'plugins.flutter.io/google_maps', - onPlatformViewCreated: onPlatformViewCreated, - gestureRecognizers: widget.gestureRecognizers, - creationParams: creationParams, - creationParamsCodec: const StandardMessageCodec(), - ); - } - - return Text( - '$defaultTargetPlatform is not yet supported by the maps plugin'); + return _googleMapsFlutterPlatform.buildView( + creationParams, + widget.gestureRecognizers, + onPlatformViewCreated, + ); } @override void initState() { super.initState(); _googleMapOptions = _GoogleMapOptions.fromWidget(widget); - _markers = _keyByMarkerId(widget.markers); - _polygons = _keyByPolygonId(widget.polygons); - _polylines = _keyByPolylineId(widget.polylines); - _circles = _keyByCircleId(widget.circles); + _markers = keyByMarkerId(widget.markers); + _polygons = keyByPolygonId(widget.polygons); + _polylines = keyByPolylineId(widget.polylines); + _circles = keyByCircleId(widget.circles); } @override @@ -285,32 +262,32 @@ class _GoogleMapState extends State { final GoogleMapController controller = await _controller.future; // ignore: unawaited_futures controller._updateMarkers( - _MarkerUpdates.from(_markers.values.toSet(), widget.markers)); - _markers = _keyByMarkerId(widget.markers); + MarkerUpdates.from(_markers.values.toSet(), widget.markers)); + _markers = keyByMarkerId(widget.markers); } void _updatePolygons() async { final GoogleMapController controller = await _controller.future; // ignore: unawaited_futures controller._updatePolygons( - _PolygonUpdates.from(_polygons.values.toSet(), widget.polygons)); - _polygons = _keyByPolygonId(widget.polygons); + PolygonUpdates.from(_polygons.values.toSet(), widget.polygons)); + _polygons = keyByPolygonId(widget.polygons); } void _updatePolylines() async { final GoogleMapController controller = await _controller.future; // ignore: unawaited_futures controller._updatePolylines( - _PolylineUpdates.from(_polylines.values.toSet(), widget.polylines)); - _polylines = _keyByPolylineId(widget.polylines); + PolylineUpdates.from(_polylines.values.toSet(), widget.polylines)); + _polylines = keyByPolylineId(widget.polylines); } void _updateCircles() async { final GoogleMapController controller = await _controller.future; // ignore: unawaited_futures controller._updateCircles( - _CircleUpdates.from(_circles.values.toSet(), widget.circles)); - _circles = _keyByCircleId(widget.circles); + CircleUpdates.from(_circles.values.toSet(), widget.circles)); + _circles = keyByCircleId(widget.circles); } Future onPlatformViewCreated(int id) async { @@ -325,45 +302,39 @@ class _GoogleMapState extends State { } } - void onMarkerTap(String markerIdParam) { - assert(markerIdParam != null); - final MarkerId markerId = MarkerId(markerIdParam); + void onMarkerTap(MarkerId markerId) { + assert(markerId != null); if (_markers[markerId]?.onTap != null) { _markers[markerId].onTap(); } } - void onMarkerDragEnd(String markerIdParam, LatLng position) { - assert(markerIdParam != null); - final MarkerId markerId = MarkerId(markerIdParam); + void onMarkerDragEnd(MarkerId markerId, LatLng position) { + assert(markerId != null); if (_markers[markerId]?.onDragEnd != null) { _markers[markerId].onDragEnd(position); } } - void onPolygonTap(String polygonIdParam) { - assert(polygonIdParam != null); - final PolygonId polygonId = PolygonId(polygonIdParam); + void onPolygonTap(PolygonId polygonId) { + assert(polygonId != null); _polygons[polygonId].onTap(); } - void onPolylineTap(String polylineIdParam) { - assert(polylineIdParam != null); - final PolylineId polylineId = PolylineId(polylineIdParam); + void onPolylineTap(PolylineId polylineId) { + assert(polylineId != null); if (_polylines[polylineId]?.onTap != null) { _polylines[polylineId].onTap(); } } - void onCircleTap(String circleIdParam) { - assert(circleIdParam != null); - final CircleId circleId = CircleId(circleIdParam); + void onCircleTap(CircleId circleId) { + assert(circleId != null); _circles[circleId].onTap(); } - void onInfoWindowTap(String markerIdParam) { - assert(markerIdParam != null); - final MarkerId markerId = MarkerId(markerIdParam); + void onInfoWindowTap(MarkerId markerId) { + assert(markerId != null); if (_markers[markerId]?.infoWindow?.onTap != null) { _markers[markerId].infoWindow.onTap(); } @@ -476,9 +447,9 @@ class _GoogleMapOptions { addIfNonNull('compassEnabled', compassEnabled); addIfNonNull('mapToolbarEnabled', mapToolbarEnabled); - addIfNonNull('cameraTargetBounds', cameraTargetBounds?._toJson()); + addIfNonNull('cameraTargetBounds', cameraTargetBounds?.toJson()); addIfNonNull('mapType', mapType?.index); - addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?._toJson()); + addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?.toJson()); addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled); addIfNonNull('scrollGesturesEnabled', scrollGesturesEnabled); addIfNonNull('tiltGesturesEnabled', tiltGesturesEnabled); diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/joint_type.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/joint_type.dart deleted file mode 100644 index ced61ba77417..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/joint_type.dart +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Joint types for [Polyline]. -@immutable -class JointType { - const JointType._(this.value); - - /// The value representing the [JointType] on the sdk. - final int value; - - /// Mitered joint, with fixed pointed extrusion equal to half the stroke width on the outside of the joint. - /// - /// Constant Value: 0 - static const JointType mitered = JointType._(0); - - /// Flat bevel on the outside of the joint. - /// - /// Constant Value: 1 - static const JointType bevel = JointType._(1); - - /// Rounded on the outside of the joint by an arc of radius equal to half the stroke width, centered at the vertex. - /// - /// Constant Value: 2 - static const JointType round = JointType._(2); -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/location.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/location.dart deleted file mode 100644 index ae299ce9583d..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/location.dart +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// A pair of latitude and longitude coordinates, stored as degrees. -class LatLng { - /// Creates a geographical location specified in degrees [latitude] and - /// [longitude]. - /// - /// The latitude is clamped to the inclusive interval from -90.0 to +90.0. - /// - /// The longitude is normalized to the half-open interval from -180.0 - /// (inclusive) to +180.0 (exclusive) - const LatLng(double latitude, double longitude) - : assert(latitude != null), - assert(longitude != null), - latitude = - (latitude < -90.0 ? -90.0 : (90.0 < latitude ? 90.0 : latitude)), - longitude = (longitude + 180.0) % 360.0 - 180.0; - - /// The latitude in degrees between -90.0 and 90.0, both inclusive. - final double latitude; - - /// The longitude in degrees between -180.0 (inclusive) and 180.0 (exclusive). - final double longitude; - - dynamic _toJson() { - return [latitude, longitude]; - } - - static LatLng _fromJson(dynamic json) { - if (json == null) { - return null; - } - return LatLng(json[0], json[1]); - } - - @override - String toString() => '$runtimeType($latitude, $longitude)'; - - @override - bool operator ==(Object o) { - return o is LatLng && o.latitude == latitude && o.longitude == longitude; - } - - @override - int get hashCode => hashValues(latitude, longitude); -} - -/// A latitude/longitude aligned rectangle. -/// -/// The rectangle conceptually includes all points (lat, lng) where -/// * lat ∈ [`southwest.latitude`, `northeast.latitude`] -/// * lng ∈ [`southwest.longitude`, `northeast.longitude`], -/// if `southwest.longitude` ≤ `northeast.longitude`, -/// * lng ∈ [-180, `northeast.longitude`] ∪ [`southwest.longitude`, 180], -/// if `northeast.longitude` < `southwest.longitude` -class LatLngBounds { - /// Creates geographical bounding box with the specified corners. - /// - /// The latitude of the southwest corner cannot be larger than the - /// latitude of the northeast corner. - LatLngBounds({@required this.southwest, @required this.northeast}) - : assert(southwest != null), - assert(northeast != null), - assert(southwest.latitude <= northeast.latitude); - - /// The southwest corner of the rectangle. - final LatLng southwest; - - /// The northeast corner of the rectangle. - final LatLng northeast; - - dynamic _toList() { - return [southwest._toJson(), northeast._toJson()]; - } - - /// Returns whether this rectangle contains the given [LatLng]. - bool contains(LatLng point) { - return _containsLatitude(point.latitude) && - _containsLongitude(point.longitude); - } - - bool _containsLatitude(double lat) { - return (southwest.latitude <= lat) && (lat <= northeast.latitude); - } - - bool _containsLongitude(double lng) { - if (southwest.longitude <= northeast.longitude) { - return southwest.longitude <= lng && lng <= northeast.longitude; - } else { - return southwest.longitude <= lng || lng <= northeast.longitude; - } - } - - /// Converts a list to [LatLngBounds]. - @visibleForTesting - static LatLngBounds fromList(dynamic json) { - if (json == null) { - return null; - } - return LatLngBounds( - southwest: LatLng._fromJson(json[0]), - northeast: LatLng._fromJson(json[1]), - ); - } - - @override - String toString() { - return '$runtimeType($southwest, $northeast)'; - } - - @override - bool operator ==(Object o) { - return o is LatLngBounds && - o.southwest == southwest && - o.northeast == northeast; - } - - @override - int get hashCode => hashValues(southwest, northeast); -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/marker.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/marker.dart deleted file mode 100644 index 480f0a379c1e..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/marker.dart +++ /dev/null @@ -1,333 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -dynamic _offsetToJson(Offset offset) { - if (offset == null) { - return null; - } - return [offset.dx, offset.dy]; -} - -/// Text labels for a [Marker] info window. -class InfoWindow { - /// Creates an immutable representation of a label on for [Marker]. - const InfoWindow({ - this.title, - this.snippet, - this.anchor = const Offset(0.5, 0.0), - this.onTap, - }); - - /// Text labels specifying that no text is to be displayed. - static const InfoWindow noText = InfoWindow(); - - /// Text displayed in an info window when the user taps the marker. - /// - /// A null value means no title. - final String title; - - /// Additional text displayed below the [title]. - /// - /// A null value means no additional text. - final String snippet; - - /// The icon image point that will be the anchor of the info window when - /// displayed. - /// - /// The image point is specified in normalized coordinates: An anchor of - /// (0.0, 0.0) means the top left corner of the image. An anchor - /// of (1.0, 1.0) means the bottom right corner of the image. - final Offset anchor; - - /// onTap callback for this [InfoWindow]. - final VoidCallback onTap; - - /// Creates a new [InfoWindow] object whose values are the same as this instance, - /// unless overwritten by the specified parameters. - InfoWindow copyWith({ - String titleParam, - String snippetParam, - Offset anchorParam, - VoidCallback onTapParam, - }) { - return InfoWindow( - title: titleParam ?? title, - snippet: snippetParam ?? snippet, - anchor: anchorParam ?? anchor, - onTap: onTapParam ?? onTap, - ); - } - - dynamic _toJson() { - final Map json = {}; - - void addIfPresent(String fieldName, dynamic value) { - if (value != null) { - json[fieldName] = value; - } - } - - addIfPresent('title', title); - addIfPresent('snippet', snippet); - addIfPresent('anchor', _offsetToJson(anchor)); - - return json; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final InfoWindow typedOther = other; - return title == typedOther.title && - snippet == typedOther.snippet && - anchor == typedOther.anchor; - } - - @override - int get hashCode => hashValues(title.hashCode, snippet, anchor); - - @override - String toString() { - return 'InfoWindow{title: $title, snippet: $snippet, anchor: $anchor}'; - } -} - -/// Uniquely identifies a [Marker] among [GoogleMap] markers. -/// -/// This does not have to be globally unique, only unique among the list. -@immutable -class MarkerId { - /// Creates an immutable identifier for a [Marker]. - MarkerId(this.value) : assert(value != null); - - /// value of the [MarkerId]. - final String value; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final MarkerId typedOther = other; - return value == typedOther.value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() { - return 'MarkerId{value: $value}'; - } -} - -/// Marks a geographical location on the map. -/// -/// A marker icon is drawn oriented against the device's screen rather than -/// the map's surface; that is, it will not necessarily change orientation -/// due to map rotations, tilting, or zooming. -@immutable -class Marker { - /// Creates a set of marker configuration options. - /// - /// Default marker options. - /// - /// Specifies a marker that - /// * is fully opaque; [alpha] is 1.0 - /// * uses icon bottom center to indicate map position; [anchor] is (0.5, 1.0) - /// * has default tap handling; [consumeTapEvents] is false - /// * is stationary; [draggable] is false - /// * is drawn against the screen, not the map; [flat] is false - /// * has a default icon; [icon] is `BitmapDescriptor.defaultMarker` - /// * anchors the info window at top center; [infoWindowAnchor] is (0.5, 0.0) - /// * has no info window text; [infoWindowText] is `InfoWindowText.noText` - /// * is positioned at 0, 0; [position] is `LatLng(0.0, 0.0)` - /// * has an axis-aligned icon; [rotation] is 0.0 - /// * is visible; [visible] is true - /// * is placed at the base of the drawing order; [zIndex] is 0.0 - /// * reports [onTap] events - /// * reports [onDragEnd] events - const Marker({ - @required this.markerId, - this.alpha = 1.0, - this.anchor = const Offset(0.5, 1.0), - this.consumeTapEvents = false, - this.draggable = false, - this.flat = false, - this.icon = BitmapDescriptor.defaultMarker, - this.infoWindow = InfoWindow.noText, - this.position = const LatLng(0.0, 0.0), - this.rotation = 0.0, - this.visible = true, - this.zIndex = 0.0, - this.onTap, - this.onDragEnd, - }) : assert(alpha == null || (0.0 <= alpha && alpha <= 1.0)); - - /// Uniquely identifies a [Marker]. - final MarkerId markerId; - - /// The opacity of the marker, between 0.0 and 1.0 inclusive. - /// - /// 0.0 means fully transparent, 1.0 means fully opaque. - final double alpha; - - /// The icon image point that will be placed at the [position] of the marker. - /// - /// The image point is specified in normalized coordinates: An anchor of - /// (0.0, 0.0) means the top left corner of the image. An anchor - /// of (1.0, 1.0) means the bottom right corner of the image. - final Offset anchor; - - /// True if the marker icon consumes tap events. If not, the map will perform - /// default tap handling by centering the map on the marker and displaying its - /// info window. - final bool consumeTapEvents; - - /// True if the marker is draggable by user touch events. - final bool draggable; - - /// True if the marker is rendered flatly against the surface of the Earth, so - /// that it will rotate and tilt along with map camera movements. - final bool flat; - - /// A description of the bitmap used to draw the marker icon. - final BitmapDescriptor icon; - - /// A Google Maps InfoWindow. - /// - /// The window is displayed when the marker is tapped. - final InfoWindow infoWindow; - - /// Geographical location of the marker. - final LatLng position; - - /// Rotation of the marker image in degrees clockwise from the [anchor] point. - final double rotation; - - /// True if the marker is visible. - final bool visible; - - /// The z-index of the marker, used to determine relative drawing order of - /// map overlays. - /// - /// Overlays are drawn in order of z-index, so that lower values means drawn - /// earlier, and thus appearing to be closer to the surface of the Earth. - final double zIndex; - - /// Callbacks to receive tap events for markers placed on this map. - final VoidCallback onTap; - - /// Signature reporting the new [LatLng] at the end of a drag event. - final ValueChanged onDragEnd; - - /// Creates a new [Marker] object whose values are the same as this instance, - /// unless overwritten by the specified parameters. - Marker copyWith({ - double alphaParam, - Offset anchorParam, - bool consumeTapEventsParam, - bool draggableParam, - bool flatParam, - BitmapDescriptor iconParam, - InfoWindow infoWindowParam, - LatLng positionParam, - double rotationParam, - bool visibleParam, - double zIndexParam, - VoidCallback onTapParam, - ValueChanged onDragEndParam, - }) { - return Marker( - markerId: markerId, - alpha: alphaParam ?? alpha, - anchor: anchorParam ?? anchor, - consumeTapEvents: consumeTapEventsParam ?? consumeTapEvents, - draggable: draggableParam ?? draggable, - flat: flatParam ?? flat, - icon: iconParam ?? icon, - infoWindow: infoWindowParam ?? infoWindow, - position: positionParam ?? position, - rotation: rotationParam ?? rotation, - visible: visibleParam ?? visible, - zIndex: zIndexParam ?? zIndex, - onTap: onTapParam ?? onTap, - onDragEnd: onDragEndParam ?? onDragEnd, - ); - } - - /// Creates a new [Marker] object whose values are the same as this instance. - Marker clone() => copyWith(); - - Map _toJson() { - final Map json = {}; - - void addIfPresent(String fieldName, dynamic value) { - if (value != null) { - json[fieldName] = value; - } - } - - addIfPresent('markerId', markerId.value); - addIfPresent('alpha', alpha); - addIfPresent('anchor', _offsetToJson(anchor)); - addIfPresent('consumeTapEvents', consumeTapEvents); - addIfPresent('draggable', draggable); - addIfPresent('flat', flat); - addIfPresent('icon', icon?._toJson()); - addIfPresent('infoWindow', infoWindow?._toJson()); - addIfPresent('position', position?._toJson()); - addIfPresent('rotation', rotation); - addIfPresent('visible', visible); - addIfPresent('zIndex', zIndex); - return json; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Marker typedOther = other; - return markerId == typedOther.markerId && - alpha == typedOther.alpha && - anchor == typedOther.anchor && - consumeTapEvents == typedOther.consumeTapEvents && - draggable == typedOther.draggable && - flat == typedOther.flat && - icon == typedOther.icon && - infoWindow == typedOther.infoWindow && - position == typedOther.position && - rotation == typedOther.rotation && - visible == typedOther.visible && - zIndex == typedOther.zIndex; - } - - @override - int get hashCode => markerId.hashCode; - - @override - String toString() { - return 'Marker{markerId: $markerId, alpha: $alpha, anchor: $anchor, ' - 'consumeTapEvents: $consumeTapEvents, draggable: $draggable, flat: $flat, ' - 'icon: $icon, infoWindow: $infoWindow, position: $position, rotation: $rotation, ' - 'visible: $visible, zIndex: $zIndex, onTap: $onTap}'; - } -} - -Map _keyByMarkerId(Iterable markers) { - if (markers == null) { - return {}; - } - return Map.fromEntries(markers.map((Marker marker) => - MapEntry(marker.markerId, marker.clone()))); -} - -List> _serializeMarkerSet(Set markers) { - if (markers == null) { - return null; - } - return markers.map>((Marker m) => m._toJson()).toList(); -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/marker_updates.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/marker_updates.dart deleted file mode 100644 index d4a08255e069..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/marker_updates.dart +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// [Marker] update events to be applied to the [GoogleMap]. -/// -/// Used in [GoogleMapController] when the map is updated. -class _MarkerUpdates { - /// Computes [_MarkerUpdates] given previous and current [Marker]s. - _MarkerUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousMarkers = _keyByMarkerId(previous); - final Map currentMarkers = _keyByMarkerId(current); - - final Set prevMarkerIds = previousMarkers.keys.toSet(); - final Set currentMarkerIds = currentMarkers.keys.toSet(); - - Marker idToCurrentMarker(MarkerId id) { - return currentMarkers[id]; - } - - final Set _markerIdsToRemove = - prevMarkerIds.difference(currentMarkerIds); - - final Set _markersToAdd = currentMarkerIds - .difference(prevMarkerIds) - .map(idToCurrentMarker) - .toSet(); - - /// Returns `true` if [current] is not equals to previous one with the - /// same id. - bool hasChanged(Marker current) { - final Marker previous = previousMarkers[current.markerId]; - return current != previous; - } - - final Set _markersToChange = currentMarkerIds - .intersection(prevMarkerIds) - .map(idToCurrentMarker) - .where(hasChanged) - .toSet(); - - markersToAdd = _markersToAdd; - markerIdsToRemove = _markerIdsToRemove; - markersToChange = _markersToChange; - } - - Set markersToAdd; - Set markerIdsToRemove; - Set markersToChange; - - Map _toMap() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull('markersToAdd', _serializeMarkerSet(markersToAdd)); - addIfNonNull('markersToChange', _serializeMarkerSet(markersToChange)); - addIfNonNull('markerIdsToRemove', - markerIdsToRemove.map((MarkerId m) => m.value).toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final _MarkerUpdates typedOther = other; - return setEquals(markersToAdd, typedOther.markersToAdd) && - setEquals(markerIdsToRemove, typedOther.markerIdsToRemove) && - setEquals(markersToChange, typedOther.markersToChange); - } - - @override - int get hashCode => - hashValues(markersToAdd, markerIdsToRemove, markersToChange); - - @override - String toString() { - return '_MarkerUpdates{markersToAdd: $markersToAdd, ' - 'markerIdsToRemove: $markerIdsToRemove, ' - 'markersToChange: $markersToChange}'; - } -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/pattern_item.dart deleted file mode 100644 index 82e8703d10e2..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/pattern_item.dart +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Item used in the stroke pattern for a Polyline. -@immutable -class PatternItem { - const PatternItem._(this._json); - - /// A dot used in the stroke pattern for a [Polyline]. - static const PatternItem dot = PatternItem._(['dot']); - - /// A dash used in the stroke pattern for a [Polyline]. - /// - /// [length] has to be non-negative. - static PatternItem dash(double length) { - assert(length >= 0.0); - return PatternItem._(['dash', length]); - } - - /// A gap used in the stroke pattern for a [Polyline]. - /// - /// [length] has to be non-negative. - static PatternItem gap(double length) { - assert(length >= 0.0); - return PatternItem._(['gap', length]); - } - - final dynamic _json; - - dynamic _toJson() => _json; -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/polygon.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/polygon.dart deleted file mode 100644 index 973667eece09..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/polygon.dart +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Uniquely identifies a [Polygon] among [GoogleMap] polygons. -/// -/// This does not have to be globally unique, only unique among the list. -@immutable -class PolygonId { - /// Creates an immutable identifier for a [Polygon]. - PolygonId(this.value) : assert(value != null); - - /// value of the [PolygonId]. - final String value; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final PolygonId typedOther = other; - return value == typedOther.value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() { - return 'PolygonId{value: $value}'; - } -} - -/// Draws a polygon through geographical locations on the map. -@immutable -class Polygon { - /// Creates an immutable representation of a polygon through geographical locations on the map. - const Polygon({ - @required this.polygonId, - this.consumeTapEvents = false, - this.fillColor = Colors.black, - this.geodesic = false, - this.points = const [], - this.strokeColor = Colors.black, - this.strokeWidth = 10, - this.visible = true, - this.zIndex = 0, - this.onTap, - }); - - /// Uniquely identifies a [Polygon]. - final PolygonId polygonId; - - /// True if the [Polygon] consumes tap events. - /// - /// If this is false, [onTap] callback will not be triggered. - final bool consumeTapEvents; - - /// Fill color in ARGB format, the same format used by Color. The default value is black (0xff000000). - final Color fillColor; - - /// Indicates whether the segments of the polygon should be drawn as geodesics, as opposed to straight lines - /// on the Mercator projection. - /// - /// A geodesic is the shortest path between two points on the Earth's surface. - /// The geodesic curve is constructed assuming the Earth is a sphere - final bool geodesic; - - /// The vertices of the polygon to be drawn. - /// - /// Line segments are drawn between consecutive points. A polygon is not closed by - /// default; to form a closed polygon, the start and end points must be the same. - final List points; - - /// True if the marker is visible. - final bool visible; - - /// Line color in ARGB format, the same format used by Color. The default value is black (0xff000000). - final Color strokeColor; - - /// Width of the polygon, used to define the width of the line to be drawn. - /// - /// The width is constant and independent of the camera's zoom level. - /// The default value is 10. - final int strokeWidth; - - /// The z-index of the polygon, used to determine relative drawing order of - /// map overlays. - /// - /// Overlays are drawn in order of z-index, so that lower values means drawn - /// earlier, and thus appearing to be closer to the surface of the Earth. - final int zIndex; - - /// Callbacks to receive tap events for polygon placed on this map. - final VoidCallback onTap; - - /// Creates a new [Polygon] object whose values are the same as this instance, - /// unless overwritten by the specified parameters. - Polygon copyWith({ - bool consumeTapEventsParam, - Color fillColorParam, - bool geodesicParam, - List pointsParam, - Color strokeColorParam, - int strokeWidthParam, - bool visibleParam, - int zIndexParam, - VoidCallback onTapParam, - }) { - return Polygon( - polygonId: polygonId, - consumeTapEvents: consumeTapEventsParam ?? consumeTapEvents, - fillColor: fillColorParam ?? fillColor, - geodesic: geodesicParam ?? geodesic, - points: pointsParam ?? points, - strokeColor: strokeColorParam ?? strokeColor, - strokeWidth: strokeWidthParam ?? strokeWidth, - visible: visibleParam ?? visible, - onTap: onTapParam ?? onTap, - zIndex: zIndexParam ?? zIndex, - ); - } - - /// Creates a new [Polygon] object whose values are the same as this instance. - Polygon clone() { - return copyWith(pointsParam: List.of(points)); - } - - dynamic _toJson() { - final Map json = {}; - - void addIfPresent(String fieldName, dynamic value) { - if (value != null) { - json[fieldName] = value; - } - } - - addIfPresent('polygonId', polygonId.value); - addIfPresent('consumeTapEvents', consumeTapEvents); - addIfPresent('fillColor', fillColor.value); - addIfPresent('geodesic', geodesic); - addIfPresent('strokeColor', strokeColor.value); - addIfPresent('strokeWidth', strokeWidth); - addIfPresent('visible', visible); - addIfPresent('zIndex', zIndex); - - if (points != null) { - json['points'] = _pointsToJson(); - } - - return json; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Polygon typedOther = other; - return polygonId == typedOther.polygonId && - consumeTapEvents == typedOther.consumeTapEvents && - fillColor == typedOther.fillColor && - geodesic == typedOther.geodesic && - listEquals(points, typedOther.points) && - visible == typedOther.visible && - strokeColor == typedOther.strokeColor && - strokeWidth == typedOther.strokeWidth && - zIndex == typedOther.zIndex; - } - - @override - int get hashCode => polygonId.hashCode; - - dynamic _pointsToJson() { - final List result = []; - for (final LatLng point in points) { - result.add(point._toJson()); - } - return result; - } -} - -Map _keyByPolygonId(Iterable polygons) { - if (polygons == null) { - return {}; - } - return Map.fromEntries(polygons.map((Polygon polygon) => - MapEntry(polygon.polygonId, polygon.clone()))); -} - -List> _serializePolygonSet(Set polygons) { - if (polygons == null) { - return null; - } - return polygons - .map>((Polygon p) => p._toJson()) - .toList(); -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/polygon_updates.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/polygon_updates.dart deleted file mode 100644 index 5a14c6b8ec5c..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/polygon_updates.dart +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// [Polygon] update events to be applied to the [GoogleMap]. -/// -/// Used in [GoogleMapController] when the map is updated. -class _PolygonUpdates { - /// Computes [_PolygonUpdates] given previous and current [Polygon]s. - _PolygonUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousPolygons = _keyByPolygonId(previous); - final Map currentPolygons = _keyByPolygonId(current); - - final Set prevPolygonIds = previousPolygons.keys.toSet(); - final Set currentPolygonIds = currentPolygons.keys.toSet(); - - Polygon idToCurrentPolygon(PolygonId id) { - return currentPolygons[id]; - } - - final Set _polygonIdsToRemove = - prevPolygonIds.difference(currentPolygonIds); - - final Set _polygonsToAdd = currentPolygonIds - .difference(prevPolygonIds) - .map(idToCurrentPolygon) - .toSet(); - - /// Returns `true` if [current] is not equals to previous one with the - /// same id. - bool hasChanged(Polygon current) { - final Polygon previous = previousPolygons[current.polygonId]; - return current != previous; - } - - final Set _polygonsToChange = currentPolygonIds - .intersection(prevPolygonIds) - .map(idToCurrentPolygon) - .where(hasChanged) - .toSet(); - - polygonsToAdd = _polygonsToAdd; - polygonIdsToRemove = _polygonIdsToRemove; - polygonsToChange = _polygonsToChange; - } - - Set polygonsToAdd; - Set polygonIdsToRemove; - Set polygonsToChange; - - Map _toMap() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull('polygonsToAdd', _serializePolygonSet(polygonsToAdd)); - addIfNonNull('polygonsToChange', _serializePolygonSet(polygonsToChange)); - addIfNonNull('polygonIdsToRemove', - polygonIdsToRemove.map((PolygonId m) => m.value).toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final _PolygonUpdates typedOther = other; - return setEquals(polygonsToAdd, typedOther.polygonsToAdd) && - setEquals(polygonIdsToRemove, typedOther.polygonIdsToRemove) && - setEquals(polygonsToChange, typedOther.polygonsToChange); - } - - @override - int get hashCode => - hashValues(polygonsToAdd, polygonIdsToRemove, polygonsToChange); - - @override - String toString() { - return '_PolygonUpdates{polygonsToAdd: $polygonsToAdd, ' - 'polygonIdsToRemove: $polygonIdsToRemove, ' - 'polygonsToChange: $polygonsToChange}'; - } -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/polyline.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/polyline.dart deleted file mode 100644 index c27b19e2843e..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/polyline.dart +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Uniquely identifies a [Polyline] among [GoogleMap] polylines. -/// -/// This does not have to be globally unique, only unique among the list. -@immutable -class PolylineId { - /// Creates an immutable object representing a [PolylineId] among [GoogleMap] polylines. - /// - /// An [AssertionError] will be thrown if [value] is null. - PolylineId(this.value) : assert(value != null); - - /// value of the [PolylineId]. - final String value; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final PolylineId typedOther = other; - return value == typedOther.value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() { - return 'PolylineId{value: $value}'; - } -} - -/// Draws a line through geographical locations on the map. -@immutable -class Polyline { - /// Creates an immutable object representing a line drawn through geographical locations on the map. - const Polyline({ - @required this.polylineId, - this.consumeTapEvents = false, - this.color = Colors.black, - this.endCap = Cap.buttCap, - this.geodesic = false, - this.jointType = JointType.mitered, - this.points = const [], - this.patterns = const [], - this.startCap = Cap.buttCap, - this.visible = true, - this.width = 10, - this.zIndex = 0, - this.onTap, - }); - - /// Uniquely identifies a [Polyline]. - final PolylineId polylineId; - - /// True if the [Polyline] consumes tap events. - /// - /// If this is false, [onTap] callback will not be triggered. - final bool consumeTapEvents; - - /// Line segment color in ARGB format, the same format used by Color. The default value is black (0xff000000). - final Color color; - - /// Indicates whether the segments of the polyline should be drawn as geodesics, as opposed to straight lines - /// on the Mercator projection. - /// - /// A geodesic is the shortest path between two points on the Earth's surface. - /// The geodesic curve is constructed assuming the Earth is a sphere - final bool geodesic; - - /// Joint type of the polyline line segments. - /// - /// The joint type defines the shape to be used when joining adjacent line segments at all vertices of the - /// polyline except the start and end vertices. See [JointType] for supported joint types. The default value is - /// mitered. - /// - /// Supported on Android only. - final JointType jointType; - - /// The stroke pattern for the polyline. - /// - /// Solid or a sequence of PatternItem objects to be repeated along the line. - /// Available PatternItem types: Gap (defined by gap length in pixels), Dash (defined by line width and dash - /// length in pixels) and Dot (circular, centered on the line, diameter defined by line width in pixels). - final List patterns; - - /// The vertices of the polyline to be drawn. - /// - /// Line segments are drawn between consecutive points. A polyline is not closed by - /// default; to form a closed polyline, the start and end points must be the same. - final List points; - - /// The cap at the start vertex of the polyline. - /// - /// The default start cap is ButtCap. - /// - /// Supported on Android only. - final Cap startCap; - - /// The cap at the end vertex of the polyline. - /// - /// The default end cap is ButtCap. - /// - /// Supported on Android only. - final Cap endCap; - - /// True if the marker is visible. - final bool visible; - - /// Width of the polyline, used to define the width of the line segment to be drawn. - /// - /// The width is constant and independent of the camera's zoom level. - /// The default value is 10. - final int width; - - /// The z-index of the polyline, used to determine relative drawing order of - /// map overlays. - /// - /// Overlays are drawn in order of z-index, so that lower values means drawn - /// earlier, and thus appearing to be closer to the surface of the Earth. - final int zIndex; - - /// Callbacks to receive tap events for polyline placed on this map. - final VoidCallback onTap; - - /// Creates a new [Polyline] object whose values are the same as this instance, - /// unless overwritten by the specified parameters. - Polyline copyWith({ - Color colorParam, - bool consumeTapEventsParam, - Cap endCapParam, - bool geodesicParam, - JointType jointTypeParam, - List patternsParam, - List pointsParam, - Cap startCapParam, - bool visibleParam, - int widthParam, - int zIndexParam, - VoidCallback onTapParam, - }) { - return Polyline( - polylineId: polylineId, - color: colorParam ?? color, - consumeTapEvents: consumeTapEventsParam ?? consumeTapEvents, - endCap: endCapParam ?? endCap, - geodesic: geodesicParam ?? geodesic, - jointType: jointTypeParam ?? jointType, - patterns: patternsParam ?? patterns, - points: pointsParam ?? points, - startCap: startCapParam ?? startCap, - visible: visibleParam ?? visible, - width: widthParam ?? width, - onTap: onTapParam ?? onTap, - zIndex: zIndexParam ?? zIndex, - ); - } - - /// Creates a new [Polyline] object whose values are the same as this - /// instance. - Polyline clone() { - return copyWith( - patternsParam: List.of(patterns), - pointsParam: List.of(points), - ); - } - - dynamic _toJson() { - final Map json = {}; - - void addIfPresent(String fieldName, dynamic value) { - if (value != null) { - json[fieldName] = value; - } - } - - addIfPresent('polylineId', polylineId.value); - addIfPresent('consumeTapEvents', consumeTapEvents); - addIfPresent('color', color.value); - addIfPresent('endCap', endCap?._toJson()); - addIfPresent('geodesic', geodesic); - addIfPresent('jointType', jointType?.value); - addIfPresent('startCap', startCap?._toJson()); - addIfPresent('visible', visible); - addIfPresent('width', width); - addIfPresent('zIndex', zIndex); - - if (points != null) { - json['points'] = _pointsToJson(); - } - - if (patterns != null) { - json['pattern'] = _patternToJson(); - } - - return json; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Polyline typedOther = other; - return polylineId == typedOther.polylineId && - consumeTapEvents == typedOther.consumeTapEvents && - color == typedOther.color && - geodesic == typedOther.geodesic && - jointType == typedOther.jointType && - listEquals(patterns, typedOther.patterns) && - listEquals(points, typedOther.points) && - startCap == typedOther.startCap && - endCap == typedOther.endCap && - visible == typedOther.visible && - width == typedOther.width && - zIndex == typedOther.zIndex; - } - - @override - int get hashCode => polylineId.hashCode; - - dynamic _pointsToJson() { - final List result = []; - for (final LatLng point in points) { - result.add(point._toJson()); - } - return result; - } - - dynamic _patternToJson() { - final List result = []; - for (final PatternItem patternItem in patterns) { - if (patternItem != null) { - result.add(patternItem._toJson()); - } - } - return result; - } -} - -Map _keyByPolylineId(Iterable polylines) { - if (polylines == null) { - return {}; - } - return Map.fromEntries(polylines.map( - (Polyline polyline) => MapEntry( - polyline.polylineId, polyline.clone()))); -} - -List> _serializePolylineSet(Set polylines) { - if (polylines == null) { - return null; - } - return polylines - .map>((Polyline p) => p._toJson()) - .toList(); -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/polyline_updates.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/polyline_updates.dart deleted file mode 100644 index ed972a51c8bf..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/polyline_updates.dart +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// [Polyline] update events to be applied to the [GoogleMap]. -/// -/// Used in [GoogleMapController] when the map is updated. -class _PolylineUpdates { - /// Computes [_PolylineUpdates] given previous and current [Polyline]s. - _PolylineUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousPolylines = - _keyByPolylineId(previous); - final Map currentPolylines = - _keyByPolylineId(current); - - final Set prevPolylineIds = previousPolylines.keys.toSet(); - final Set currentPolylineIds = currentPolylines.keys.toSet(); - - Polyline idToCurrentPolyline(PolylineId id) { - return currentPolylines[id]; - } - - final Set _polylineIdsToRemove = - prevPolylineIds.difference(currentPolylineIds); - - final Set _polylinesToAdd = currentPolylineIds - .difference(prevPolylineIds) - .map(idToCurrentPolyline) - .toSet(); - - /// Returns `true` if [current] is not equals to previous one with the - /// same id. - bool hasChanged(Polyline current) { - final Polyline previous = previousPolylines[current.polylineId]; - return current != previous; - } - - final Set _polylinesToChange = currentPolylineIds - .intersection(prevPolylineIds) - .map(idToCurrentPolyline) - .where(hasChanged) - .toSet(); - - polylinesToAdd = _polylinesToAdd; - polylineIdsToRemove = _polylineIdsToRemove; - polylinesToChange = _polylinesToChange; - } - - Set polylinesToAdd; - Set polylineIdsToRemove; - Set polylinesToChange; - - Map _toMap() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull('polylinesToAdd', _serializePolylineSet(polylinesToAdd)); - addIfNonNull('polylinesToChange', _serializePolylineSet(polylinesToChange)); - addIfNonNull('polylineIdsToRemove', - polylineIdsToRemove.map((PolylineId m) => m.value).toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final _PolylineUpdates typedOther = other; - return setEquals(polylinesToAdd, typedOther.polylinesToAdd) && - setEquals(polylineIdsToRemove, typedOther.polylineIdsToRemove) && - setEquals(polylinesToChange, typedOther.polylinesToChange); - } - - @override - int get hashCode => - hashValues(polylinesToAdd, polylineIdsToRemove, polylinesToChange); - - @override - String toString() { - return '_PolylineUpdates{polylinesToAdd: $polylinesToAdd, ' - 'polylineIdsToRemove: $polylineIdsToRemove, ' - 'polylinesToChange: $polylinesToChange}'; - } -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/screen_coordinate.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/screen_coordinate.dart deleted file mode 100644 index e58abe9cefad..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/screen_coordinate.dart +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Represents a point coordinate in the [GoogleMap]'s view. -/// -/// The screen location is specified in screen pixels (not display pixels) relative -/// to the top left of the map, not top left of the whole screen. (x, y) = (0, 0) -/// corresponds to top-left of the [GoogleMap] not the whole screen. -@immutable -class ScreenCoordinate { - /// Creates an immutable representation of a point coordinate in the [GoogleMap]'s view. - const ScreenCoordinate({ - @required this.x, - @required this.y, - }); - - /// Represents the number of pixels from the left of the [GoogleMap]. - final int x; - - /// Represents the number of pixels from the top of the [GoogleMap]. - final int y; - - dynamic _toJson() { - return { - "x": x, - "y": y, - }; - } - - @override - String toString() => '$runtimeType($x, $y)'; - - @override - bool operator ==(Object o) { - return o is ScreenCoordinate && o.x == x && o.y == y; - } - - @override - int get hashCode => hashValues(x, y); -} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/ui.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/ui.dart deleted file mode 100644 index 4b57ebd7440f..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/ui.dart +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of google_maps_flutter; - -/// Type of map tiles to display. -// Enum constants must be indexed to match the corresponding int constants of -// the Android platform API, see -// -enum MapType { - /// Do not display map tiles. - none, - - /// Normal tiles (traffic and labels, subtle terrain information). - normal, - - /// Satellite imaging tiles (aerial photos) - satellite, - - /// Terrain tiles (indicates type and height of terrain) - terrain, - - /// Hybrid tiles (satellite images with some labels/overlays) - hybrid, -} - -/// Bounds for the map camera target. -// Used with [GoogleMapOptions] to wrap a [LatLngBounds] value. This allows -// distinguishing between specifying an unbounded target (null `LatLngBounds`) -// from not specifying anything (null `CameraTargetBounds`). -class CameraTargetBounds { - /// Creates a camera target bounds with the specified bounding box, or null - /// to indicate that the camera target is not bounded. - const CameraTargetBounds(this.bounds); - - /// The geographical bounding box for the map camera target. - /// - /// A null value means the camera target is unbounded. - final LatLngBounds bounds; - - /// Unbounded camera target. - static const CameraTargetBounds unbounded = CameraTargetBounds(null); - - dynamic _toJson() => [bounds?._toList()]; - - @override - bool operator ==(dynamic other) { - if (identical(this, other)) return true; - if (runtimeType != other.runtimeType) return false; - final CameraTargetBounds typedOther = other; - return bounds == typedOther.bounds; - } - - @override - int get hashCode => bounds.hashCode; - - @override - String toString() { - return 'CameraTargetBounds(bounds: $bounds)'; - } -} - -/// Preferred bounds for map camera zoom level. -// Used with [GoogleMapOptions] to wrap min and max zoom. This allows -// distinguishing between specifying unbounded zooming (null `minZoom` and -// `maxZoom`) from not specifying anything (null `MinMaxZoomPreference`). -class MinMaxZoomPreference { - /// Creates a immutable representation of the preferred minimum and maximum zoom values for the map camera. - /// - /// [AssertionError] will be thrown if [minZoom] > [maxZoom]. - const MinMaxZoomPreference(this.minZoom, this.maxZoom) - : assert(minZoom == null || maxZoom == null || minZoom <= maxZoom); - - /// The preferred minimum zoom level or null, if unbounded from below. - final double minZoom; - - /// The preferred maximum zoom level or null, if unbounded from above. - final double maxZoom; - - /// Unbounded zooming. - static const MinMaxZoomPreference unbounded = - MinMaxZoomPreference(null, null); - - dynamic _toJson() => [minZoom, maxZoom]; - - @override - bool operator ==(dynamic other) { - if (identical(this, other)) return true; - if (runtimeType != other.runtimeType) return false; - final MinMaxZoomPreference typedOther = other; - return minZoom == typedOther.minZoom && maxZoom == typedOther.maxZoom; - } - - @override - int get hashCode => hashValues(minZoom, maxZoom); - - @override - String toString() { - return 'MinMaxZoomPreference(minZoom: $minZoom, maxZoom: $maxZoom)'; - } -} - -/// Exception when a map style is invalid or was unable to be set. -/// -/// See also: `setStyle` on [GoogleMapController] for why this exception -/// might be thrown. -class MapStyleException implements Exception { - /// Default constructor for [MapStyleException]. - const MapStyleException(this.cause); - - /// The reason `GoogleMapController.setStyle` would throw this exception. - final String cause; -} diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 7831934ba972..89fd66a0197e 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -1,12 +1,13 @@ name: google_maps_flutter description: A Flutter plugin for integrating Google Maps in iOS and Android applications. homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter -version: 0.5.26+4 +version: 0.5.27 dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^1.0.0 + google_maps_flutter_platform_interface: ^1.0.1 dev_dependencies: flutter_test: @@ -27,6 +28,8 @@ flutter: pluginClass: GoogleMapsPlugin ios: pluginClass: FLTGoogleMapsPlugin + web: + default_package: google_maps_flutter_web environment: sdk: ">=2.0.0-dev.47.0 <3.0.0"