-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
146 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## [2.0.1] | ||
|
||
* Customizable shapes layer. | ||
|
||
## [2.0.0+1] | ||
|
||
* Dependencies updated. | ||
|
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
part of '../../map.dart'; | ||
|
||
/// Raster or Vector data for a specific [z, x, y] coordinate. | ||
/// | ||
/// This class must be a child of [MapLayout]. | ||
class ShapeLayer extends StatefulWidget { | ||
/// Main constructor. | ||
const ShapeLayer({ | ||
Key? key, | ||
required this.transformer, | ||
required this.shapes, | ||
}) : super(key: key); | ||
|
||
/// The transformer from parent. | ||
final MapTransformer transformer; | ||
|
||
/// Shapes to display on the Map. | ||
final List<Shape> shapes; | ||
|
||
@override | ||
State<StatefulWidget> createState() => _ShapeLayerState(); | ||
} | ||
|
||
/// Represents a polygon. | ||
class Shape { | ||
/// Constructor. | ||
const Shape({ | ||
required this.points, | ||
required this.painter, | ||
this.metadata, | ||
}); | ||
|
||
/// Geo coordinates. | ||
final List<LatLng> points; | ||
|
||
/// Optional metadata that comes with the shape. | ||
final Object? metadata; | ||
|
||
/// Painter. | ||
final void Function(Canvas canvas, Path shape, Object? metadata) painter; | ||
} | ||
|
||
class _ShapeLayerState extends State<ShapeLayer> { | ||
@override | ||
void didChangeDependencies() { | ||
final map = context.findAncestorWidgetOfExactType<MapLayout>(); | ||
|
||
if (map == null) { | ||
throw Exception('TileLayer must be used inside a MapLayout.'); | ||
} | ||
|
||
super.didChangeDependencies(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CustomPaint( | ||
painter: _ShapePainter( | ||
transformer: widget.transformer, | ||
shapes: widget.shapes, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _ShapePainter extends CustomPainter { | ||
const _ShapePainter({ | ||
required this.transformer, | ||
required this.shapes, | ||
}); | ||
|
||
final MapTransformer transformer; | ||
final List<Shape> shapes; | ||
|
||
@override | ||
void paint(Canvas canvas, Size size) { | ||
for (var shape in shapes) { | ||
final points = transformer.toOffsetMany(shape.points).toList(); | ||
|
||
Path f = Path(); | ||
f.addPolygon(points, true); | ||
|
||
shape.painter(canvas, f, shape.metadata); | ||
} | ||
} | ||
|
||
@override | ||
bool shouldRepaint(covariant CustomPainter oldDelegate) { | ||
return false; | ||
} | ||
} |
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