From 261db4064db2243a40d9f55e221a715ccc998325 Mon Sep 17 00:00:00 2001 From: Luka S Date: Sun, 24 Nov 2024 12:29:25 +0000 Subject: [PATCH] feat: expose `BaseOverlayImage` for external implementation (#1990) --- .../overlay_image_layer/overlay_image.dart | 38 ++++++++++++------- .../overlay_image_layer.dart | 1 - 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/src/layer/overlay_image_layer/overlay_image.dart b/lib/src/layer/overlay_image_layer/overlay_image.dart index cd8958dfc..22ab1565b 100644 --- a/lib/src/layer/overlay_image_layer/overlay_image.dart +++ b/lib/src/layer/overlay_image_layer/overlay_image.dart @@ -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. @@ -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, @@ -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), ); } @@ -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( camera.project(this.bounds.northWest) - camera.pixelOrigin, @@ -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; diff --git a/lib/src/layer/overlay_image_layer/overlay_image_layer.dart b/lib/src/layer/overlay_image_layer/overlay_image_layer.dart index 324ed66cd..7e7922781 100644 --- a/lib/src/layer/overlay_image_layer/overlay_image_layer.dart +++ b/lib/src/layer/overlay_image_layer/overlay_image_layer.dart @@ -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';