Skip to content

result event is invoked twice #99

Closed

Description

@andrewharvey

http://jsbin.com/nalopux/edit?html,console,output

If I type something in the Geocoder then select an option, the result event is seemingly invoked twice with the same result.

Activity

  1. changed the title [-]result event is called twice[/-] [+]result event is invoked twice[/+] on Feb 15, 2017
  2. andrewharvey commented on Feb 23, 2017

    @andrewharvey
    CollaboratorAuthor

    This is an upstream issue in suggestions, see tristen/suggestions#13

  3. brambow commented on Jun 13, 2017

    @brambow

    This is causing issues for me in a situation where I am trying to animate some layers that contain the resulting point of a geocode operation. Since the result is invoked twice, my animation runs twice and looks weird. Any ideas for a workaround appreciated.

  4. andrewharvey commented on Jun 13, 2017

    @andrewharvey
    CollaboratorAuthor

    @brambow Do you mind testing the proposed solution at tristen/suggestions#13

    If I disable the dispatch of the change event at https://github.com/tristen/suggestions/blob/gh-pages/src/suggestions.js#L151 the event is only triggered once and there doesn't seem to be any side affects.

    I didn't notice any issue, if you don't either we can try to get a fix for this!

  5. brambow commented on Jun 13, 2017

    @brambow

    Yep. That seems to fix it.

  6. ckc11 commented on Jun 13, 2017

    @ckc11

    This also fixed it for me as well.

  7. andrewharvey commented on Jul 7, 2017

    @andrewharvey
    CollaboratorAuthor

    Just noting that removing this code does fix it for modern browsers but breaks it for IE11. tristen/suggestions#13 (comment)

  8. jwhazel commented on Aug 3, 2017

    @jwhazel

    Throwing in my request for a fix as well (preferably one that satisfies IE11). My current solution is to set up global to store the latlng and check to see if the new event is different than the last. Clearly not the most elegant solution.

    lastGeocode = "";
    geocoder.on('result', function (e) {
        if(e.result.center.toString() !== lastGeocode){
            drawCustomMarker(e.result.center, e.result.place_name);
        }
    
        lastGeocode = e.result.center.toString();
    });
    
  9. pathmapper commented on Sep 2, 2018

    @pathmapper

    Using GL JS v0.48.0 and Geocoder v2.3.0, it looks like the behavior changed a bit compared to #99 (comment):

    The second result event is now fired after a click on the map (Chrome on Linux):
    https://jsbin.com/dapurelime/edit?html,console,output

  10. andrewharvey commented on Sep 3, 2018

    @andrewharvey
    CollaboratorAuthor

    The second result event is now fired after a click on the map (Chrome on Linux):

    That's interesting, I'm also running Chrome on Linux and can't replicate that, in fact I'm only ever seeing the result event emitted once. 🤔

  11. pathmapper commented on Sep 3, 2018

    @pathmapper

    @andrewharvey sometimes I also see only one result event.

    It seems like it depends on

    • what you are searching for
    • which option is selected (if there are more than one)
    • if there were geocoder searches before without reloading the page

    With the following steps I get always a second result event after a click with the left mouse button (just noticed that the click must not be necessarily on the map, e.g. a click on the console triggers also the 2nd event):

    1. Type Miami in the Geocoder of the jsbin I've posted above.
    2. Just hit enter on your keybord.
    3. Click on the map with the left mouse button.
  12. andrewharvey commented on Sep 3, 2018

    @andrewharvey
    CollaboratorAuthor

    @pathmapper Right, that's because hitting enter selects the result, but doesn't blur the input, only when you click the map does the input blur and it triggers result again.

    I believe that points back to tristen/suggestions#13 where the issue was ensuring result is triggered in all interactions (keyboard, mouse) across all supported browsers (IE11 was the issue), it was easy to fix for modern browsers, but I couldn't find a way to fix it such that it didn't break IE11.

  13. added this to the v4.0.0 milestone on Mar 13, 2019
  14. added a commit that references this issue on Mar 19, 2019
  15. andrewharvey commented on Mar 21, 2019

    @andrewharvey
    CollaboratorAuthor

    #218 implemented a workaround the underlying bug in the upstream suggestions library. So I'll go ahead and close this as the bug shouldn't be noticeable to end users anymore. This is slated for v4 release.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions