-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Markers with Annotations #248
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
🚀 New features to boost your workflow:
|
Sorry for your long wait for a response @pamtbaau. I finally had time to look at your pull requests in detail. I still think that adding marker annotation is a great idea - so let's try solving the alignment issues. I recommend to enable the "Show Guidelines" option in the flutter dev tools while working with Markers to see the outlines. Marker(
point: Position(0, 0),
size: const Size.square(150),
child: Container(color: Colors.red, width: 150, height: 150),
), ![]() When we change ![]() We are now able to align the text for example to the center right side using a Marker(
point: Position(0, 0),
size: const Size.square(150),
child: const Align(
alignment: Alignment.centerRight,
child: Text(
'Marker',
style: TextStyle(color: Colors.red, fontSize: 20),
),
),
), ![]() We could use the same for annotations where the ![]() Complete code sample of the screenshot (click to expand)
import 'package:flutter/material.dart';
import 'package:maplibre/maplibre.dart';
@immutable
class WidgetLayerPage extends StatefulWidget {
const WidgetLayerPage({super.key});
static const location = '/widget-layer';
@override
State<WidgetLayerPage> createState() => _WidgetLayerPageState();
}
class _WidgetLayerPageState extends State<WidgetLayerPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Widget Layer')),
body: MapLibreMap(
options: MapOptions(initZoom: 3, initCenter: Position(0, 0)),
children: [
WidgetLayer(
markers: [
Marker(
point: Position(0, 0),
size: const Size.square(150),
child: const _Marker(),
annotations: const [
Annotation(
child: _Annotation(),
alignment: Alignment.topLeft,
),
Annotation(
child: _Annotation(),
alignment: Alignment.topCenter,
),
Annotation(
child: _Annotation(),
alignment: Alignment.topRight,
),
Annotation(
child: _Annotation(),
alignment: Alignment.centerLeft,
),
Annotation(
child: Text(
'centerLeft',
style: TextStyle(
color: Colors.purpleAccent,
fontSize: 30,
),
),
alignment: Alignment.centerLeft,
),
// Annotation(
// child: _Annotation(),
// alignment: Alignment.center,
// ),
Annotation(
child: _Annotation(),
alignment: Alignment.centerRight,
),
Annotation(
child: _Annotation(),
alignment: Alignment.bottomLeft,
),
// Annotation(
// child: _Annotation(),
// alignment: Alignment.bottomCenter,
// ),
Annotation(
child: _Annotation(),
alignment: Alignment.bottomRight,
),
],
),
],
),
// display the UI widgets above the widget markers.
const SourceAttribution(),
],
),
);
}
}
class _Annotation extends StatelessWidget {
const _Annotation();
@override
Widget build(BuildContext context) {
return Container(color: Colors.purple, width: 20, height: 20);
}
}
class _Marker extends StatelessWidget {
const _Marker();
@override
Widget build(BuildContext context) {
return Container(color: Colors.red, width: 150, height: 150);
}
}
To sum it all up, I'd do the following changes
Calculating the used height of the font is a nice idea, but I'm not sure if it would cause some problems, for example if the user increased the size of all texts on the device. |
As discussed, I've created this PR to discuss the possible implementation of Annotations to Markers.
Summary:
Annotation can have any widget as child, including Gestures.
List<Annotation> annotations
to class Markerbuild()
to create and position Annotations relative to MarkerSize _calculateTextSize(Text textWidget)
to calculate width and height of Text widget needed to horizontally/vertically align with centers of Marker.Issue:
Any feedback/suggestion is welcome.