Skip to content

Commit

Permalink
feat: expose BaseOverlayImage for external implementation (#1990)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaffaKetchup authored Nov 24, 2024
1 parent 2e64369 commit 261db40
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
38 changes: 24 additions & 14 deletions lib/src/layer/overlay_image_layer/overlay_image.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
part of 'overlay_image_layer.dart';

/// Base class for all overlay images.
/// Display an [Image] on the map at a specific coordinate location, within an
/// [OverlayImageLayer]
///
/// Implemented by [OverlayImage] & [RotatedOverlayImage].
@immutable
sealed class BaseOverlayImage extends StatelessWidget {
/// The [ImageProvider] for the image.
abstract class BaseOverlayImage extends StatelessWidget {
/// The [ImageProvider] to use within the [Image] widget.
final ImageProvider imageProvider;

/// The opacity in which the image should get rendered on the map.
Expand All @@ -17,6 +20,7 @@ sealed class BaseOverlayImage extends StatelessWidget {
/// overlay image should have on the map.
final FilterQuality filterQuality;

/// Display an [Image] on the map at a specific coordinate location
const BaseOverlayImage({
super.key,
required this.imageProvider,
Expand All @@ -25,25 +29,29 @@ sealed class BaseOverlayImage extends StatelessWidget {
this.filterQuality = FilterQuality.medium,
});

Widget _render(
/// Given the [child] image to display, return the layout (ie. position &
/// transformation) of the child
///
/// Use [MapCamera.of] to retrieve the ambient [MapCamera] useful for layout.
///
/// If more control over the [Image] itself is required, prefer subclassing
/// one of the existing subclasses and overriding [build].
@protected
Widget layout(
BuildContext context, {
required Image child,
required MapCamera camera,
});

@override
@nonVirtual
Widget build(BuildContext context) => _render(
Widget build(BuildContext context) => layout(
context,
child: Image(
image: imageProvider,
fit: BoxFit.fill,
color: Color.fromRGBO(255, 255, 255, opacity),
colorBlendMode: BlendMode.modulate,
opacity: AlwaysStoppedAnimation(opacity),
gaplessPlayback: gaplessPlayback,
filterQuality: filterQuality,
),
camera: MapCamera.of(context),
);
}

Expand All @@ -67,11 +75,12 @@ class OverlayImage extends BaseOverlayImage {
});

@override
Widget _render(
Widget layout(
BuildContext context, {
required Image child,
required MapCamera camera,
}) {
final camera = MapCamera.of(context);

// northWest is not necessarily upperLeft depending on projection
final bounds = Bounds<double>(
camera.project(this.bounds.northWest) - camera.pixelOrigin,
Expand Down Expand Up @@ -120,11 +129,12 @@ class RotatedOverlayImage extends BaseOverlayImage {
});

@override
Widget _render(
Widget layout(
BuildContext context, {
required Image child,
required MapCamera camera,
}) {
final camera = MapCamera.of(context);

final pxTopLeft = camera.project(topLeftCorner) - camera.pixelOrigin;
final pxBottomRight =
camera.project(bottomRightCorner) - camera.pixelOrigin;
Expand Down
1 change: 0 additions & 1 deletion lib/src/layer/overlay_image_layer/overlay_image_layer.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
Expand Down

0 comments on commit 261db40

Please sign in to comment.