Skip to content

Commit

Permalink
[Example] Implement the changePosition function for place_fill exampl…
Browse files Browse the repository at this point in the history
…e. (#778)
  • Loading branch information
Kevin Li authored Nov 19, 2021
1 parent b26debb commit 4641f23
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions example/lib/place_fill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ class PlaceFillBodyState extends State<PlaceFillBody> {
static final LatLng center = const LatLng(-33.86711, 151.1947171);
final String _fillPatternImage = "assets/fill/cat_silhouette_pattern.png";

final List<List<LatLng>> _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;
Expand Down Expand Up @@ -72,21 +88,7 @@ class PlaceFillBodyState extends State<PlaceFillBody> {

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;
Expand All @@ -102,7 +104,20 @@ class PlaceFillBodyState extends State<PlaceFillBody> {
}

void _changePosition() {
//TODO: Implement change position.
List<List<LatLng>>? 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() {
Expand Down

0 comments on commit 4641f23

Please sign in to comment.