mapbox / mapbox/mapbox-maps-flutter

The longPress event is fired only after the finger is released

Open
#1,118 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
380
Forks
204
PR merge metrics
No merged PRs in 30d

Description

Here’s what I want to achieve: I want to create a map object (using PointAnnotationManager) on a long tap. However, the action doesn't trigger until I release my finger, which isn't very intuitive for the user. The PointAnnotationManager behaves the same way. I would like to implement a long press that, once triggered, allows the user to immediately drag the object across the map. Is there an option to make the long press behave in a more traditional way?

```
MapWidget(
key: const Key('AppMap--MapWidget'),

styleUri:
controller.repository.localStorage.load(
'map_type',
) ??
MapboxStyles.OUTDOORS,
cameraOptions: controller.initialCameraOptions,
onMapCreated: controller.onMapCreated,
onCameraChangeListener: controller.onCameraChangeListener,
onLongTapListener: controller.onLongTapListener,
onTapListener: controller.onTapListener,
onStyleLoadedListener: controller.onStyleLoadedListener,
),
```

```
Future initAnnotations({
required PointAnnotationManager pointManagerIcon,
required PointAnnotationManager pointManagerLabel,
}) async {
await pointManagerIcon.setIconRotationAlignment(
IconRotationAlignment.MAP,
);
await pointManagerLabel.setIconRotationAlignment(
IconRotationAlignment.VIEWPORT,
);

_pointManagerIcon = pointManagerIcon;
_pointManagerLabel = pointManagerLabel;

_pointManagerLabel.tapEvents(
onTap: _onTapMapLabel,
);

_pointManagerIcon.dragEvents(
onEnd: _onDragEnd,
);

_pointManagerIcon.longPressEvents(
onLongPress: _onLongPress,
);
}
```

```
Future _createIconPointAnnotation({
required LatLng location,
required Uint8List image,
required String imageId,
required LocatedObjectModel locatedObject,
}) async {
final annotation = PointAnnotationOptions(
customData: {
"image_id": imageId,
},
geometry: Point(
coordinates: Position(location.longitude, location.latitude),
),

image: image,
iconRotate: _iconRotateFromAzimuth(locatedObject.directionAzimuthDegree),
//isDraggable: user.isAdmin || user.isOperator,
);
return _pointManagerIcon.create(annotation);
}
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from MapWidget's onLongTapListener and the PointAnnotationManager longPressEvents and dragEvents shown in the report. Inspect how long-press recognition and annotation dragging are connected, then determine whether the gesture can trigger before release while preserving drag behavior. Done means a long press activates during the touch and lets the user immediately drag the annotation.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.