Skip to content

Commit

Permalink
fixes for android
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Sep 23, 2024
1 parent f73199f commit 1cb7c1b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions example/lib/animation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ class _AnimationPageState extends State<AnimationPage> {
jsonDecode(geojsonLine) as Map<String, Object?>,
);
final lineString = geojson.features.first.geometry! as LineString;
// TODO: setting the id is currently required as geotypes would set it to null, Feature.id documented at https://datatracker.ietf.org/doc/html/rfc7946#section-3.2
geojson.features.first.id = 1;
final allCoords = lineString.coordinates;

lineString.coordinates = List.empty();
// a LineString on MapLibre Native must have at least 2 Points
lineString.coordinates = allCoords.sublist(0,2);
await _controller.addSource(
GeoJsonSource(id: _sourceId, data: jsonEncode(geojson.toJson())),
);
Expand All @@ -57,12 +60,14 @@ class _AnimationPageState extends State<AnimationPage> {
);

var index = 1;
_timer = Timer.periodic(const Duration(milliseconds: 100), (timer) {
if (index > allCoords.length) {
_timer = Timer.periodic(const Duration(milliseconds: 1), (timer) {
index++;
if (index > allCoords.length -1) {
debugPrint('line animation completed');
timer.cancel();
return;
}
lineString.coordinates = allCoords.sublist(0, index++);
lineString.coordinates = allCoords.sublist(0, index);
_controller.updateGeoJsonSource(
id: _sourceId,
data: jsonEncode(geojson.toJson()),
Expand Down

0 comments on commit 1cb7c1b

Please sign in to comment.