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

cherry-pick upstream#825 #97

Merged
merged 1 commit into from
May 22, 2022
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:maplibre_gl/mapbox_gl.dart';

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

void _onMapCreated(MaplibreMapController controller) {
this.controller = controller;
Expand All @@ -45,6 +48,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 @@ -99,6 +109,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 @@ -123,6 +141,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 @@ -177,6 +196,12 @@ class LineBodyState extends State<LineBody> {
await _move();
},
),
TextButton(
child: const Text('change line-pattern'),
onPressed: (_selectedLine == null)
? null
: _changeLinePattern,
),
],
),
Row(
Expand Down