Skip to content
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
25 changes: 25 additions & 0 deletions example/lib/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mapbox_gl/mapbox_gl.dart';

import 'main.dart';
Expand Down Expand Up @@ -34,6 +36,7 @@ class LineBodyState extends State<LineBody> {
MapboxMapController? controller;
int _lineCount = 0;
Line? _selectedLine;
final String _linePatternImage = "assets/fill/cat_silhouette_pattern.png";

void _onMapCreated(MapboxMapController controller) {
this.controller = controller;
Expand All @@ -46,6 +49,13 @@ class LineBodyState extends State<LineBody> {
super.dispose();
}

/// Adds an asset image to the currently displayed style
Future<void> addImageFromAsset(String name, String assetName) async {
final ByteData bytes = await rootBundle.load(assetName);
final Uint8List list = bytes.buffer.asUint8List();
return controller!.addImage(name, list);
}

_onLineTapped(Line line) async {
await _updateSelectedLine(
LineOptions(lineColor: "#ff0000"),
Expand Down Expand Up @@ -100,6 +110,14 @@ class LineBodyState extends State<LineBody> {
});
}

Future<void> _changeLinePattern() async {
String? current =
_selectedLine!.options.linePattern == null ? "assetImage" : null;
await _updateSelectedLine(
LineOptions(linePattern: current),
);
}

Future<void> _changeAlpha() async {
double? current = _selectedLine!.options.lineOpacity;
if (current == null) {
Expand All @@ -124,6 +142,7 @@ class LineBodyState extends State<LineBody> {
}

_onStyleLoadedCallback() async {
addImageFromAsset("assetImage", _linePatternImage);
await controller!.addLine(
LineOptions(
geometry: [LatLng(37.4220, -122.0841), LatLng(37.4240, -122.0941)],
Expand Down Expand Up @@ -179,6 +198,12 @@ class LineBodyState extends State<LineBody> {
await _move();
},
),
TextButton(
child: const Text('change line-pattern'),
onPressed: (_selectedLine == null)
? null
: _changeLinePattern,
),
],
),
Row(
Expand Down