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

[Example] Implement the changePosition function for place_fill example. #778

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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