Skip to content

Commit

Permalink
Cherry-pick upstream#778 (#75)
Browse files Browse the repository at this point in the history
* Cherry-pick upstream#778 ([Example] Implement the changePosition function for place_fill example.)

https: //github.com/flutter-mapbox-gl/maps/pull/778

Co-authored-by: Kevin Li <kevin.li@mapbox.com>
  • Loading branch information
m0nac0 and Kevin Li authored May 14, 2022
1 parent 0e3bcee commit e922602
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions example/lib/place_fill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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),
]
];

MaplibreMapController? controller;
int _fillCount = 0;
Fill? _selectedFill;
Expand Down Expand Up @@ -71,21 +87,10 @@ 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 @@ -101,7 +106,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 e922602

Please sign in to comment.