Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose BaseOverlayImage for external implementation #1990

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading