From 4641f23796fee4be90e8b5e3986eb60be50449cf Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Fri, 19 Nov 2021 19:35:34 +0800 Subject: [PATCH] [Example] Implement the changePosition function for place_fill example. (#778) --- example/lib/place_fill.dart | 47 ++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/example/lib/place_fill.dart b/example/lib/place_fill.dart index 74c6187e1..8a39daee3 100644 --- a/example/lib/place_fill.dart +++ b/example/lib/place_fill.dart @@ -34,6 +34,22 @@ class PlaceFillBodyState extends State { static final LatLng center = const LatLng(-33.86711, 151.1947171); final String _fillPatternImage = "assets/fill/cat_silhouette_pattern.png"; + final List> _defaultGeometry = [ + [ + LatLng(-33.719, 151.150), + LatLng(-33.858, 151.150), + LatLng(-33.866, 151.401), + LatLng(-33.747, 151.328), + LatLng(-33.719, 151.150), + ], + [ + LatLng(-33.762, 151.250), + LatLng(-33.827, 151.250), + LatLng(-33.833, 151.347), + LatLng(-33.762, 151.250), + ] + ]; + MapboxMapController? controller; int _fillCount = 0; Fill? _selectedFill; @@ -72,21 +88,7 @@ class PlaceFillBodyState extends State { void _add() { controller!.addFill( - FillOptions(geometry: [ - [ - LatLng(-33.719, 151.150), - LatLng(-33.858, 151.150), - LatLng(-33.866, 151.401), - LatLng(-33.747, 151.328), - LatLng(-33.719, 151.150), - ], - [ - LatLng(-33.762, 151.250), - LatLng(-33.827, 151.250), - LatLng(-33.833, 151.347), - LatLng(-33.762, 151.250), - ] - ], fillColor: "#FF0000", fillOutlineColor: "#FF0000"), + FillOptions(geometry: _defaultGeometry, fillColor: "#FF0000", fillOutlineColor: "#FF0000"), ); setState(() { _fillCount += 1; @@ -102,7 +104,20 @@ class PlaceFillBodyState extends State { } void _changePosition() { - //TODO: Implement change position. + List>? geometry = _selectedFill!.options.geometry; + + if (geometry == null) { + geometry = _defaultGeometry; + } + + _updateSelectedFill(FillOptions( + geometry: geometry + .map((list) => list + .map( + // Move to right with 0.1 degree on longitude + (latLng) => LatLng(latLng.latitude, latLng.longitude + 0.1)) + .toList()) + .toList())); } void _changeDraggable() {