Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

MarkerClick event is only raised once #3176

Closed

Description

@bobmeyers5

The concept of a tap/click input event and the default response to that event (select the marker and show info window) seem conflated in the current implementation. This causes problems when the input events are important, but the "selection" state is not.

The most critical problem is that a tap/click on a marker always moves the marker into the "selected" state (regardless of the MarkerClick event handler's return value), and once in this state, additional tap/click input no longer raises the MarkerClick event. When selection state is not important/visible to the user, it is not obvious to them how to fix this. In addition, there is no easy way at the code level to prevent it from happening.

Some specifics contributing to the confusion:

  • A tap/click on an unselected marker always moves it to the "selected" state, even if mOnMarkerClickListener.onMarkerClick returns false, indicating the input event was "handled".
  • A tap/click on a selected marker does not raise the MarkerClick event, even though the associated input event clearly occurred.
  • Calling selectMarker raises the MarkerClick event, even though the method name doesn't say anything about simulating a particular input event, and the event name suggests a particular input event occurred (which it did not).
  • The default visual indicator of a marker's selection state is the presence or absence of an info window. However, this is not reliable because an info window may not be defined, it may be prevented from appearing due to the MarkerClick event returning false, and it may be shown and hidden independently by calling methods on the Marker object directly, none of which have any effect on the marker's selection state.

Unfortunately, because the current implementation is so confusing, one cannot be sure exactly how the code is currently being used, and therefore almost any fix could be considered a breaking change for some scenarios.

In the long term, though:

  • MapView.onSingleTapConfirmed should raise the MarkerClick event any time the input event occurs, regardless of the marker's selection state.
  • If the MarkerClick event handler returns false, the entire default response to that input, including any selection state change, should be skipped.
  • A new MarkerSelectionChanged event should be introduced to allow input events and selection state changes to be handled separately.
  • MapView.selectMarker should raise the new MarkerSelectionChanged event, and should not raise MarkerClick.

Activity

  1. added
    Android
    on Dec 8, 2015
  2. added this to the milestone on Dec 8, 2015
  3. tobrun commented on Jan 19, 2016

    @tobrun
    Member

    @bmeyers43
    Thank you for reaching out and giving us such detailed feedback. The subject here is something that we are improving/documenting in #553. I'm going to close this one down in favour of that one. I linked this issue so we can pickup this up.

  4. bobmeyers5 commented on Jan 19, 2016

    @bobmeyers5
    Author

    That's a pretty massive work item ("One does not simply imitate Google's robust gesture system!") and it sounds like it's entirely about gesture recognition, not about the API for handling gestures after they have been recognized. My issue is just about fixing the API for handling simple tap/click events and changes to marker selection state. You may want to follow a similar pattern when exposing other gesture events, but I really don't want to wait for you to reimplement your whole gesture recognition system before I can get a reliable marker click event!

    Could you please consider fixing this separately (and sooner)?

    --Bob


    From: Tobrunmailto:[email protected]
    Sent: ‎1/‎19/‎2016 4:39 AM
    To: mapbox/mapbox-gl-nativemailto:[email protected]
    Cc: bmeyers43mailto:[email protected]
    Subject: Re: [mapbox-gl-native] MarkerClick event is only raised once (#3176)

    @bmeyers43
    Thank you for reaching out and giving us such detailed feedback. The subject here is something that we are improving/documenting in #553. I'm going to close this one down in favour of that one. I linked this issue so we can pickup this up.


    Reply to this email directly or view it on GitHub:
    #3176 (comment)

  5. tobrun commented on Jan 20, 2016

    @tobrun
    Member

    @bmeyers43
    You are right about that being about recognition vs selection state. Reopening and putting this issue on my priority list. Thank again for writing up this issue. This type of feedback is very valuable!

    I'm seeing 2 actionable things here:

    • The general one is that onMarkerClick callback invocation is not correctly positioned.
      Instead of in selectMarker it should be moved to onSingleTapConfirmed (now tapping a selected marker also results in a callback + solves is this method name/event appropriate problem).
    • The second one is introduce a new callback system around MarkerSelectionChanged

    I'm not 💯 on the second one though, is this API you would use or ideally want? Google Maps SDK is currently not exposing this. I have no problem adding it but I would like to support this with a use-case that isn't solvable with a correctly working onMarkerClick integration.

  6. reopened this on Jan 20, 2016
  7. bobmeyers5 commented on Jan 20, 2016

    @bobmeyers5
    Author

    The biggest issue currently is that no event is raised in response to a tap once the marker is selected. This issue could be resolved by either (or preferably both) of the following changes:

    • Call onMarkerClick in onSingleTapConfirmed so it gets raised regardless of selection state.
    • Don't call selectMarker if onMarkerClick returns false (indicating the event was handled).

    In addition, I think you should consider adding an onMarkerSelectionChanged callback, but this is up to you. If someone is allowing the default behavior of click -> select, then they can probably use the onMarkerClick callback as a proxy in most cases. However it is common in general for controls that maintain selection state for a list of subitems to expose events around changes to the selection state. These callbacks would be invoked both in response to user input (e.g. a tap/click) and programmatic changes to selection state. If Google Maps doesn't expose anything like this and no one else is clamoring for it, I understand if it's not a high priority anytime soon. I myself don't need it at the moment either.

  8. 9 remaining items

  9. modified the milestone: android-v4.1.0 on Mar 18, 2016
  10. nealsanche commented on May 11, 2016

    @nealsanche

    I'd be completely happy with the current marker click functionality in 4.1.0-SNAPSHOT if this:

                    mMapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
                        @Override
                        public boolean onMarkerClick(@NonNull Marker marker) {
                            Toast.makeText(MainActivity.this, "Marker tapped: " + marker.getTitle(), Toast.LENGTH_LONG).show();
                            return true;
                        }
                    });
    

    Would pop the toast every time. Notice I returned 'true' there. That's the cue to say that I've handled this event myself and I don't want default behaviour. Thing is, the default behaviour is still happening (though not showing the info window) and so the second tap doesn't pop a toast, only every second tap pops a toast.

  11. SilkSama commented on Jul 1, 2016

    @SilkSama

    Ugly workaround but it work for me waiting a better solution

    @OverRide
    public boolean onMarkerClick(@nonnull Marker marker) {
    ...
    new Handler().postDelayed(() -> mMapboxMap.deselectMarker(marker), 100);
    return true;
    }

  12. TostF commented on Jul 26, 2016

    @TostF

    @SilkSama hack is working.
    Problem here is that the OnMarkerClickListener does not represent the task that it is doing.
    At the moment OnMarkerClickListener should be called OnMarkerSelectedListener.

  13. jemshit commented on Oct 19, 2016

    @jemshit

    @bobmeyers5 That is very nice description of problem 👍

  14. tobrun commented on Dec 6, 2016

    @tobrun
    Member

    I focussed on resolving the business logic issues as set out in the OP:

    • MapView.onSingleTapConfirmed should raise the MarkerClick event any time the input event occurs, regardless of the marker's selection state.

    • If the MarkerClick event handler returns false true, the entire default response to that input, including any selection state change, should be skipped.

    Related to the other items mentioned in the OP as OnMarkerSelectionChangeListener. I'm thinking of PR'ing current progress and handling that as a separate feature request.

  15. FreedApe770 commented on Mar 13, 2017

    @FreedApe770

    @SilkSama Why do I need to use the "Handler().postDelayed(() -> mMapboxMap.deselectMarker(marker), 100);" rather than the “mMapboxMap.deselectMarker(marker)”? I know the latter is no effect, but I would like to know the reason.
    Thank you very much!

  16. tobrun commented on Mar 13, 2017

    @tobrun
    Member

    @jwen1989 the workaround is no longer applicable, you should be able to get it your use-case working without it. Feel free to add more information or create a separate ticket.

  17. FreedApe770 commented on Mar 23, 2017

    @FreedApe770

    @tobrun Thank you for your advice。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Androidbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions