fleaflet / flutter_map

A versatile mapping package for Flutter. Simple and easy to learn, yet completely customizable and configurable, it's the best choice for mapping in your Flutter app.
https://pub.dev/packages/flutter_map
BSD 3-Clause "New" or "Revised" License
2.76k stars 863 forks source link

[SPEC] Overhaul gesture system #1715

Open josxha opened 1 year ago

josxha commented 1 year ago

Request for comments

Motivation

As mentioned by @JaffaKetchup in https://github.com/fleaflet/flutter_map/issues/1529#issue-1718239936, "much of the [gesture handling] code that does this was written in the first few releases, and has not been significantly changed since. [...] Gesture handling at this low-level often differs slightly between platforms, which means that manual testing succeeds on one platform, but a bug occurs on another."

Rewrite Proposals

If feasible do the following changes:

More resources

josxha commented 1 year ago
Example implementation of the new `InteractiveFlags` class ```dart @immutable class InteractiveFlags { const InteractiveFlags._({ required this.drag, required this.flingAnimation, required this.pinchMove, required this.pinchZoom, required this.doubleTapZoom, required this.doubleTapDragZoom, required this.scrollWheelZoom, required this.rotate, }); const InteractiveFlags.all({ this.drag = true, this.flingAnimation = true, this.pinchMove = true, this.pinchZoom = true, this.doubleTapZoom = true, this.doubleTapDragZoom = true, this.scrollWheelZoom = true, this.rotate = true, }); const InteractiveFlags.none({ this.drag = false, this.flingAnimation = false, this.pinchMove = false, this.pinchZoom = false, this.doubleTapZoom = false, this.doubleTapDragZoom = false, this.scrollWheelZoom = false, this.rotate = false, }); /// Enable panning with a single finger or cursor final bool drag; /// Enable fling animation after panning if velocity is great enough. final bool flingAnimation; /// Enable panning with multiple fingers final bool pinchMove; /// Enable zooming with a multi-finger pinch gesture final bool pinchZoom; /// Enable zooming with a single-finger double tap gesture final bool doubleTapZoom; /// Enable zooming with a single-finger double-tap-drag gesture /// /// The associated [MapEventSource] is [MapEventSource.doubleTapHold]. final bool doubleTapDragZoom; /// Enable zooming with a mouse scroll wheel final bool scrollWheelZoom; /// Enable rotation with two-finger twist gesture /// /// For controlling cursor/keyboard rotation, see /// [InteractionOptions.cursorKeyboardRotationOptions]. final bool rotate; bool hasMultiFinger() => pinchMove || pinchZoom || rotate; /// This constructor gives wither functionality to the model InteractiveFlags withFlag({ bool? pinchZoom, bool? drag, bool? flingAnimation, bool? pinchMove, bool? doubleTapZoom, bool? doubleTapDragZoom, bool? scrollWheelZoom, bool? rotate, }) => InteractiveFlags._( pinchZoom: pinchZoom ?? this.pinchZoom, drag: drag ?? this.drag, flingAnimation: flingAnimation ?? this.flingAnimation, pinchMove: pinchMove ?? this.pinchMove, doubleTapZoom: doubleTapZoom ?? this.doubleTapZoom, doubleTapDragZoom: doubleTapDragZoom ?? this.doubleTapDragZoom, scrollWheelZoom: scrollWheelZoom ?? this.scrollWheelZoom, rotate: rotate ?? this.rotate, ); } ```

This would make the following changes:

 final int flags;
// turns into
final InteractiveFlags flags;

flags: InteractiveFlags.all - InteractiveFlags.rotate,
// turns into
flags: InteractiveFlags.all(rotate: false), 

if (InteractiveFlag.hasDoubleTapZoom(newOptions.flags)) {
// turns into
if (newOptions.flags.doubleTapZoom) {
hobleyd commented 1 year ago

If we are looking at this, could it be possible to add a feature request to be able to get a LatLng from a click on the map please?

JaffaKetchup commented 1 year ago

Hi @hobleyd, This is already possible. Use onTap inside MapOptions. Unless I'm misunderstanding something?

hobleyd commented 1 year ago

Thanks. I missed that. Humblest apologies.

JaffaKetchup commented 1 year ago

No worries!

josxha commented 1 year ago

Currently blocked by:

JaffaKetchup commented 1 year ago

I think the rough rule on scope of animations is I think the rough rule is we provide basic animations in response to gestures only. It's for plugins to provide animations for programmatic controls.