-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support raster layers in the theme so that raster tile images can be combined with vector tile data. Raster layers are defined by the style spec https://docs.mapbox.com/style-spec/reference/layers/#raster
- Loading branch information
1 parent
2cf0aa2
commit 7239af9
Showing
13 changed files
with
138 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ enum ThemeLayerType { | |
line, | ||
symbol, | ||
background, | ||
raster, | ||
unsupported | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:flutter/painting.dart'; | ||
|
||
import '../../vector_tile_renderer.dart'; | ||
import '../context.dart'; | ||
import '../features/extensions.dart'; | ||
import 'expression/expression.dart'; | ||
import 'selector.dart'; | ||
|
||
class RasterPaintModel { | ||
final Expression<double> opacity; | ||
|
||
RasterPaintModel({required this.opacity}); | ||
} | ||
|
||
class ThemeLayerRaster extends ThemeLayer { | ||
final TileLayerSelector selector; | ||
final RasterPaintModel paintModel; | ||
ThemeLayerRaster(super.id, super.type, | ||
{required this.selector, | ||
required this.paintModel, | ||
required super.minzoom, | ||
required super.maxzoom, | ||
required super.metadata}); | ||
|
||
@override | ||
void render(Context context) { | ||
final image = context.tileSource.rasterTileset.tiles[tileSource]; | ||
if (image != null) { | ||
renderImage(context, image); | ||
} | ||
} | ||
|
||
void renderImage(Context context, RasterTile image) { | ||
final evaluationContext = EvaluationContext( | ||
() => {}, TileFeatureType.none, context.logger, | ||
zoom: context.zoom, | ||
zoomScaleFactor: context.zoomScaleFactor, | ||
hasImage: context.hasImage); | ||
final opacity = paintModel.opacity.evaluate(evaluationContext) ?? 1.0; | ||
if (opacity > 0.0) { | ||
final paint = Paint() | ||
..color = Color.fromARGB((opacity * 255).round().clamp(0, 255), 0, 0, 0) | ||
..isAntiAlias = true; | ||
if (image.scope == context.tileSpace) { | ||
context.canvas | ||
.drawImageRect(image.image, image.scope, context.tileSpace, paint); | ||
} else { | ||
final scale = context.tileClip.width / image.scope.width; | ||
context.canvas.drawAtlas( | ||
image.image, | ||
[ | ||
RSTransform.fromComponents( | ||
rotation: 0.0, | ||
scale: scale, | ||
anchorX: 0.0, | ||
anchorY: 0.0, | ||
translateX: context.tileClip.left, | ||
translateY: context.tileClip.top), | ||
], | ||
[image.scope], | ||
null, | ||
null, | ||
null, | ||
paint); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
String? get tileSource => selector.tileSelector.source; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'dart:ui'; | ||
|
||
/// A raster tile is an image with a corresponding scope defining the portion of | ||
/// the image that is in scope for the tile. | ||
class RasterTile { | ||
final Image image; | ||
final Rect scope; | ||
|
||
RasterTile({required this.image, required this.scope}); | ||
} | ||
|
||
/// A raster tileset is a collection of raster tiles (images) by `'source'` ID, | ||
/// as defined by the theme. | ||
class RasterTileset { | ||
final Map<String, RasterTile> tiles; | ||
|
||
const RasterTileset({required this.tiles}); | ||
|
||
void dispose() { | ||
for (var tile in tiles.values) { | ||
tile.image.dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters