Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Dart code
  • Loading branch information
stuartmorgan-g committed Nov 13, 2024
commit ac985222ab6ee47ae78a5921f572ffc96d871fe4
Original file line number Diff line number Diff line change
Expand Up @@ -590,29 +590,106 @@ class GoogleMapsFlutterIOS extends GoogleMapsFlutterPlatform {
return PlatformPoint(x: offset.dx, y: offset.dy);
}

static PlatformSize _platformSizeFromSize(Size size) {
return PlatformSize(width: size.width, height: size.height);
}

static PlatformCircle _platformCircleFromCircle(Circle circle) {
return PlatformCircle(json: circle.toJson());
return PlatformCircle(
consumeTapEvents: circle.consumeTapEvents,
fillColor: circle.fillColor.value,
strokeColor: circle.strokeColor.value,
visible: circle.visible,
strokeWidth: circle.strokeWidth,
zIndex: circle.zIndex.toDouble(),
center: _platformLatLngFromLatLng(circle.center),
radius: circle.radius,
circleId: circle.circleId.value,
);
}

static PlatformHeatmap _platformHeatmapFromHeatmap(Heatmap heatmap) {
return PlatformHeatmap(json: serializeHeatmap(heatmap));
}

static PlatformInfoWindow _platformInfoWindowFromInfoWindow(
InfoWindow window) {
return PlatformInfoWindow(
title: window.title,
snippet: window.snippet,
anchor: _platformPointFromOffset(window.anchor));
}

static PlatformMarker _platformMarkerFromMarker(Marker marker) {
return PlatformMarker(json: marker.toJson());
return PlatformMarker(
alpha: marker.alpha,
anchor: _platformPointFromOffset(marker.anchor),
consumeTapEvents: marker.consumeTapEvents,
draggable: marker.draggable,
flat: marker.flat,
icon: platformBitmapFromBitmapDescriptor(marker.icon),
infoWindow: _platformInfoWindowFromInfoWindow(marker.infoWindow),
position: _platformLatLngFromLatLng(marker.position),
rotation: marker.rotation,
visible: marker.visible,
zIndex: marker.zIndex,
markerId: marker.markerId.value,
clusterManagerId: marker.clusterManagerId?.value,
);
}

static PlatformPolygon _platformPolygonFromPolygon(Polygon polygon) {
return PlatformPolygon(json: polygon.toJson());
final List<PlatformLatLng> points =
polygon.points.map(_platformLatLngFromLatLng).toList();
final List<List<PlatformLatLng>> holes =
polygon.holes.map((List<LatLng> hole) {
return hole.map(_platformLatLngFromLatLng).toList();
}).toList();
return PlatformPolygon(
polygonId: polygon.polygonId.value,
fillColor: polygon.fillColor.value,
geodesic: polygon.geodesic,
consumesTapEvents: polygon.consumeTapEvents,
points: points,
holes: holes,
strokeColor: polygon.strokeColor.value,
strokeWidth: polygon.strokeWidth,
zIndex: polygon.zIndex,
visible: polygon.visible,
);
}

static PlatformPolyline _platformPolylineFromPolyline(Polyline polyline) {
return PlatformPolyline(json: polyline.toJson());
final List<PlatformLatLng> points =
polyline.points.map(_platformLatLngFromLatLng).toList();
final List<PlatformPatternItem> pattern =
polyline.patterns.map(platformPatternItemFromPatternItem).toList();
return PlatformPolyline(
polylineId: polyline.polylineId.value,
consumesTapEvents: polyline.consumeTapEvents,
color: polyline.color.value,
startCap: platformCapFromCap(polyline.startCap),
endCap: platformCapFromCap(polyline.endCap),
geodesic: polyline.geodesic,
visible: polyline.visible,
width: polyline.width,
zIndex: polyline.zIndex,
points: points,
jointType: platformJointTypeFromJointType(polyline.jointType),
patterns: pattern,
);
}

static PlatformTileOverlay _platformTileOverlayFromTileOverlay(
TileOverlay tileOverlay) {
return PlatformTileOverlay(json: tileOverlay.toJson());
return PlatformTileOverlay(
tileOverlayId: tileOverlay.tileOverlayId.value,
fadeIn: tileOverlay.fadeIn,
transparency: tileOverlay.transparency,
zIndex: tileOverlay.zIndex,
visible: tileOverlay.visible,
tileSize: tileOverlay.tileSize,
);
}

static PlatformClusterManager _platformClusterManagerFromClusterManager(
Expand Down Expand Up @@ -673,6 +750,94 @@ class GoogleMapsFlutterIOS extends GoogleMapsFlutterPlatform {
PlatformCameraUpdateScrollBy(dx: update.dx, dy: update.dy));
}
}

/// Convert [MapBitmapScaling] from platform interface to [PlatformMapBitmapScaling] Pigeon.
Copy link
Member

@cbracken cbracken Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and (a couple times, but not all times) below: ultra pedantic nit:

Suggested change
/// Convert [MapBitmapScaling] from platform interface to [PlatformMapBitmapScaling] Pigeon.
/// Converts [MapBitmapScaling] from platform interface to [PlatformMapBitmapScaling] Pigeon.

https://dart.dev/effective-dart/documentation#prefer-starting-function-or-method-comments-with-third-person-verbs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a nit I usually leave, so I'm happy to fix it :) I didn't notice when I pasted these in from Android.

@visibleForTesting
static PlatformMapBitmapScaling platformMapBitmapScalingFromScaling(
MapBitmapScaling scaling) {
switch (scaling) {
case MapBitmapScaling.auto:
return PlatformMapBitmapScaling.auto;
case MapBitmapScaling.none:
return PlatformMapBitmapScaling.none;
}

// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return PlatformMapBitmapScaling.auto;
}

/// Convert [BitmapDescriptor] from platform interface to [PlatformBitmap] pigeon.
@visibleForTesting
static PlatformBitmap platformBitmapFromBitmapDescriptor(
BitmapDescriptor bitmap) {
switch (bitmap) {
case final DefaultMarker marker:
return PlatformBitmap(
bitmap: PlatformBitmapDefaultMarker(hue: marker.hue?.toDouble()));
case final BytesBitmap bytes:
final Size? size = bytes.size;
return PlatformBitmap(
bitmap: PlatformBitmapBytes(
byteData: bytes.byteData,
size: (size == null) ? null : _platformSizeFromSize(size)));
case final AssetBitmap asset:
return PlatformBitmap(
bitmap: PlatformBitmapAsset(name: asset.name, pkg: asset.package));
case final AssetImageBitmap asset:
final Size? size = asset.size;
return PlatformBitmap(
bitmap: PlatformBitmapAssetImage(
name: asset.name,
scale: asset.scale,
size: (size == null) ? null : _platformSizeFromSize(size)));
case final AssetMapBitmap asset:
return PlatformBitmap(
bitmap: PlatformBitmapAssetMap(
assetName: asset.assetName,
bitmapScaling:
platformMapBitmapScalingFromScaling(asset.bitmapScaling),
imagePixelRatio: asset.imagePixelRatio,
width: asset.width,
height: asset.height));
case final BytesMapBitmap bytes:
return PlatformBitmap(
bitmap: PlatformBitmapBytesMap(
byteData: bytes.byteData,
bitmapScaling:
platformMapBitmapScalingFromScaling(bytes.bitmapScaling),
imagePixelRatio: bytes.imagePixelRatio,
width: bytes.width,
height: bytes.height));
default:
throw ArgumentError(
'Unrecognized type of bitmap ${bitmap.runtimeType}', 'bitmap');
}
}

/// Convert [Cap] from platform interface to [PlatformCap] pigeon.
@visibleForTesting
static PlatformCap platformCapFromCap(Cap cap) {
switch (cap.type) {
case CapType.butt:
return PlatformCap(type: PlatformCapType.buttCap);
case CapType.square:
return PlatformCap(type: PlatformCapType.squareCap);
case CapType.round:
return PlatformCap(type: PlatformCapType.roundCap);
case CapType.custom:
cap as CustomCap;
return PlatformCap(
type: PlatformCapType.customCap,
bitmapDescriptor:
platformBitmapFromBitmapDescriptor(cap.bitmapDescriptor),
refWidth: cap.refWidth);
}
}
}

/// Callback handler for map events from the platform host.
Expand Down Expand Up @@ -1009,6 +1174,52 @@ PlatformZoomRange? _platformZoomRangeFromMinMaxZoomPreferenceJson(
return PlatformZoomRange(min: minMaxZoom[0], max: minMaxZoom[1]);
}

/// Converts platform interface's JointType to Pigeon's PlatformJointType.
@visibleForTesting
PlatformJointType platformJointTypeFromJointType(JointType jointType) {
switch (jointType) {
case JointType.mitered:
return PlatformJointType.mitered;
case JointType.bevel:
return PlatformJointType.bevel;
case JointType.round:
return PlatformJointType.round;
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return PlatformJointType.mitered;
}

/// Converts a PatternItem to Pigeon's PlatformPatternItem for PlatformPolyline
/// pattern member.
@visibleForTesting
PlatformPatternItem platformPatternItemFromPatternItem(PatternItem item) {
switch (item.type) {
case PatternItemType.dot:
return PlatformPatternItem(type: PlatformPatternItemType.dot);
case PatternItemType.dash:
final double length = (item as VariableLengthPatternItem).length;
return PlatformPatternItem(
type: PlatformPatternItemType.dash, length: length);
case PatternItemType.gap:
final double length = (item as VariableLengthPatternItem).length;
return PlatformPatternItem(
type: PlatformPatternItemType.gap, length: length);
}

// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return PlatformPatternItem(type: PlatformPatternItemType.dot);
}

/// Update specification for a set of [TileOverlay]s.
// TODO(stuartmorgan): Fix the missing export of this class in the platform
// interface, and remove this copy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
google_maps_flutter_platform_interface: ^2.9.4
google_maps_flutter_platform_interface: ^2.9.5
stream_transform: ^2.0.0

dev_dependencies:
Expand Down