Skip to content

Commit

Permalink
Merge branch 'main' into feat/user-location-2
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Oct 6, 2024
2 parents 44f4275 + 9745aba commit a148d9c
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 181 deletions.
30 changes: 16 additions & 14 deletions example/lib/annotations_circle_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ class AnnotationsCirclePage extends StatefulWidget {
}

class _AnnotationsCirclePageState extends State<AnnotationsCirclePage> {
final _layer = CircleAnnotationLayer(
points: <Point>[
Point(coordinates: Position(9.17, 47.68)),
Point(coordinates: Position(9.17, 48)),
Point(coordinates: Position(9, 48)),
Point(coordinates: Position(9.5, 48)),
],
color: Colors.orange.withOpacity(0.5),
radius: 20,
strokeColor: Colors.red,
strokeWidth: 2,
);
final _points = <Point>[
Point(coordinates: Position(9.17, 47.68)),
Point(coordinates: Position(9.17, 48)),
Point(coordinates: Position(9, 48)),
Point(coordinates: Position(9.5, 48)),
];

@override
Widget build(BuildContext context) {
Expand All @@ -34,11 +28,19 @@ class _AnnotationsCirclePageState extends State<AnnotationsCirclePage> {
onEvent: (event) {
if (event case MapEventClick()) {
setState(() {
_layer.list.add(Point(coordinates: event.point));
_points.add(Point(coordinates: event.point));
});
}
},
layers: [_layer],
layers: [
CircleAnnotationLayer(
points: _points,
color: Colors.orange.withOpacity(0.5),
radius: 20,
strokeColor: Colors.red,
strokeWidth: 2,
),
],
),
);
}
Expand Down
34 changes: 18 additions & 16 deletions example/lib/annotations_marker_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@ class AnnotationsMarkerPage extends StatefulWidget {
}

class _AnnotationsMarkerPageState extends State<AnnotationsMarkerPage> {
final _layer = MarkerAnnotationLayer(
points: <Point>[
Point(coordinates: Position(9.17, 47.68)),
Point(coordinates: Position(9.17, 48)),
Point(coordinates: Position(9, 48)),
Point(coordinates: Position(9.5, 48)),
],
textField: 'Marker',
textAllowOverlap: true,
iconImage: 'marker',
iconSize: 0.08,
iconAnchor: IconAnchor.bottom,
textOffset: const [0, 1],
);
final _points = <Point>[
Point(coordinates: Position(9.17, 47.68)),
Point(coordinates: Position(9.17, 48)),
Point(coordinates: Position(9, 48)),
Point(coordinates: Position(9.5, 48)),
];

late final MapController _controller;

Expand All @@ -50,14 +42,24 @@ class _AnnotationsMarkerPageState extends State<AnnotationsMarkerPage> {
case MapEventClick():
// add a new marker on click
setState(() {
_layer.list.add(Point(coordinates: event.point));
_points.add(Point(coordinates: event.point));
});
default:
// ignore all other events
break;
}
},
layers: [_layer],
layers: [
MarkerAnnotationLayer(
points: _points,
textField: 'Marker',
textAllowOverlap: true,
iconImage: 'marker',
iconSize: 0.08,
iconAnchor: IconAnchor.bottom,
textOffset: const [0, 1],
),
],
),
);
}
Expand Down
105 changes: 105 additions & 0 deletions example/lib/annotations_mixed_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:maplibre/maplibre.dart';

@immutable
class AnnotationsMixedPage extends StatefulWidget {
const AnnotationsMixedPage({super.key});

static const location = '/annotations/mixed';

@override
State<AnnotationsMixedPage> createState() => _AnnotationsMixedPageState();
}

class _AnnotationsMixedPageState extends State<AnnotationsMixedPage> {
final _random = Random.secure();
final _circlePoints = <Point>[
Point(coordinates: Position(9.17, 47.68)),
Point(coordinates: Position(9.17, 48)),
Point(coordinates: Position(9, 48)),
Point(coordinates: Position(9.5, 48)),
];
Color _circleColor = Colors.orange.withOpacity(0.5);
PolylineAnnotationLayer? _polylineLayer;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Mixed Annotations')),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(8),
child: Wrap(
spacing: 8,
alignment: WrapAlignment.center,
children: [
OutlinedButton(
onPressed: () {
setState(() {
_circleColor =
Color(_random.nextInt(0xFFFFFF) + 0x7F000000);
});
},
child: const Text(
'Change color',
textAlign: TextAlign.center,
),
),
OutlinedButton(
onPressed: () {
setState(() {
if (_polylineLayer == null) {
_polylineLayer = PolylineAnnotationLayer(
polylines: [
LineString(
coordinates: [
Position(9.17, 47.68),
Position(9.5, 48),
Position(9, 48),
],
),
],
);
} else {
_polylineLayer = null;
}
});
},
child: const Text(
'Toggle 2nd layer',
textAlign: TextAlign.center,
),
),
],
),
),
Expanded(
child: MapLibreMap(
options: MapOptions(zoom: 7, center: Position(9.17, 47.68)),
onEvent: (event) {
if (event case MapEventClick()) {
setState(() {
_circlePoints.add(Point(coordinates: event.point));
});
}
},
layers: [
CircleAnnotationLayer(
points: _circlePoints,
color: _circleColor,
radius: 20,
strokeColor: Colors.red,
strokeWidth: 2,
),
if (_polylineLayer case final AnnotationLayer layer) layer,
],
),
),
],
),
);
}
}
34 changes: 18 additions & 16 deletions example/lib/annotations_polygon_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ class AnnotationsPolygonPage extends StatefulWidget {
}

class _AnnotationsPolygonPageState extends State<AnnotationsPolygonPage> {
final _layer = PolygonAnnotationLayer(
polygons: <Polygon>[
Polygon(
coordinates: [
[
Position(9.17, 47.68),
Position(9.5, 48),
Position(9, 48),
],
final _polygons = <Polygon>[
Polygon(
coordinates: [
[
Position(9.17, 47.68),
Position(9.5, 48),
Position(9, 48),
],
),
],
color: Colors.lightBlueAccent.withOpacity(0.6),
outlineColor: Colors.blue,
);
],
),
];

@override
Widget build(BuildContext context) {
Expand All @@ -37,11 +33,17 @@ class _AnnotationsPolygonPageState extends State<AnnotationsPolygonPage> {
onEvent: (event) {
if (event case MapEventClick()) {
setState(() {
_layer.list.first.coordinates.first.add(event.point);
_polygons.first.coordinates.first.add(event.point);
});
}
},
layers: [_layer],
layers: [
PolygonAnnotationLayer(
polygons: _polygons,
color: Colors.lightBlueAccent.withOpacity(0.6),
outlineColor: Colors.blue,
),
],
),
);
}
Expand Down
36 changes: 19 additions & 17 deletions example/lib/annotations_polyline_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ class AnnotationsPolylinePage extends StatefulWidget {
}

class _AnnotationsPolylinePageState extends State<AnnotationsPolylinePage> {
final _layer = PolylineAnnotationLayer(
polylines: <LineString>[
LineString(
coordinates: [
Position(9.17, 47.68),
Position(9.5, 48),
Position(9, 48),
],
),
],
color: Colors.red,
width: 4,
blur: 3,
dashArray: const [5, 5],
);
final _polylines = <LineString>[
LineString(
coordinates: [
Position(9.17, 47.68),
Position(9.5, 48),
Position(9, 48),
],
),
];

@override
Widget build(BuildContext context) {
Expand All @@ -38,11 +32,19 @@ class _AnnotationsPolylinePageState extends State<AnnotationsPolylinePage> {
onEvent: (event) {
if (event case MapEventClick()) {
setState(() {
_layer.list.first.coordinates.add(event.point);
_polylines.first.coordinates.add(event.point);
});
}
},
layers: [_layer],
layers: [
PolylineAnnotationLayer(
polylines: _polylines,
color: Colors.red,
width: 4,
blur: 3,
dashArray: const [5, 5],
),
],
),
);
}
Expand Down
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:maplibre_example/animation_page.dart';
import 'package:maplibre_example/annotations_circle_page.dart';
import 'package:maplibre_example/annotations_marker_page.dart';
import 'package:maplibre_example/annotations_mixed_page.dart';
import 'package:maplibre_example/annotations_polygon_page.dart';
import 'package:maplibre_example/annotations_polyline_page.dart';
import 'package:maplibre_example/controller_page.dart';
Expand Down Expand Up @@ -58,6 +59,8 @@ class MyApp extends StatelessWidget {
LayersRasterPage.location: (context) => const LayersRasterPage(),
LayersLinePage.location: (context) => const LayersLinePage(),
WebControlsPage.location: (context) => const WebControlsPage(),
AnnotationsMixedPage.location: (context) =>
const AnnotationsMixedPage(),
AnnotationsCirclePage.location: (context) =>
const AnnotationsCirclePage(),
AnnotationsMarkerPage.location: (context) =>
Expand Down
6 changes: 6 additions & 0 deletions example/lib/menu_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:maplibre_example/animation_page.dart';
import 'package:maplibre_example/annotations_circle_page.dart';
import 'package:maplibre_example/annotations_marker_page.dart';
import 'package:maplibre_example/annotations_mixed_page.dart';
import 'package:maplibre_example/annotations_polygon_page.dart';
import 'package:maplibre_example/annotations_polyline_page.dart';
import 'package:maplibre_example/controller_page.dart';
Expand Down Expand Up @@ -91,6 +92,11 @@ class MenuPage extends StatelessWidget {
maxCrossAxisExtent: 200,
childAspectRatio: 1.5,
children: const [
ItemCard(
label: 'Mixed Annotations',
iconData: Icons.control_point_duplicate_outlined,
location: AnnotationsMixedPage.location,
),
ItemCard(
label: 'Circles',
iconData: Icons.circle,
Expand Down
2 changes: 1 addition & 1 deletion lib/maplibre.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// the dependency themselves.
export 'package:geotypes/geotypes.dart';

export 'src/annotation/annotations.dart';
export 'src/annotation/annotation_layer.dart';
export 'src/lng_lat_bounds.dart';
export 'src/map.dart';
export 'src/map_camera.dart';
Expand Down
Loading

0 comments on commit a148d9c

Please sign in to comment.