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

Feature: Post process tiles #582

Merged
merged 7 commits into from Mar 16, 2021
30 changes: 24 additions & 6 deletions lib/src/layer/tile_layer.dart
Expand Up @@ -83,6 +83,10 @@ class TileLayerOptions extends LayerOptions {
///Color shown behind the tiles.
final Color backgroundColor;

/// ColorFilter for the tiles to implement grayscale or similar effects.
/// https://api.flutter.dev/flutter/dart-ui/ColorFilter/ColorFilter.matrix.html
final ColorFilter colorFilter;

///Opacity of the rendered tile
final double opacity;

Expand Down Expand Up @@ -171,6 +175,7 @@ class TileLayerOptions extends LayerOptions {
this.tms = false,
// ignore: avoid_init_to_null
this.wmsOptions = null,
this.colorFilter = null,
this.opacity = 1.0,
// Tiles will not update more than once every `updateInterval` milliseconds
// (default 200) when panning.
Expand Down Expand Up @@ -347,14 +352,26 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
for (var tile in tilesToRender) _createTileWidget(tile)
];

var content = options.colorFilter == null
? Container(
color: options.backgroundColor,
child: Stack(
children: tileWidgets,
),
)
: ColorFiltered(
colorFilter: options.colorFilter,
child: Container(
color: options.backgroundColor,
child: Stack(
children: tileWidgets,
),
),
);

matthiasdittmer marked this conversation as resolved.
Show resolved Hide resolved
return Opacity(
opacity: options.opacity,
child: Container(
color: options.backgroundColor,
child: Stack(
children: tileWidgets,
),
),
child: content,
);
}

Expand Down Expand Up @@ -906,6 +923,7 @@ class Tile implements Comparable<Tile> {
DateTime loaded;

AnimationController animationController;

double get opacity => animationController == null
? (active ? 1.0 : 0.0)
: animationController.value;
Expand Down