Skip to content
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

result event is invoked twice #99

Closed
andrewharvey opened this issue Feb 15, 2017 · 12 comments
Closed

result event is invoked twice #99

andrewharvey opened this issue Feb 15, 2017 · 12 comments
Labels
Milestone

Comments

@andrewharvey
Copy link
Collaborator

andrewharvey commented Feb 15, 2017

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.

@andrewharvey andrewharvey changed the title result event is called twice result event is invoked twice Feb 15, 2017
@andrewharvey
Copy link
Collaborator Author

andrewharvey commented Feb 23, 2017

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

@brambow
Copy link

brambow commented Jun 13, 2017

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.

@andrewharvey
Copy link
Collaborator Author

@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!

@brambow
Copy link

brambow commented Jun 13, 2017

Yep. That seems to fix it.

@ckc11
Copy link

ckc11 commented Jun 13, 2017

This also fixed it for me as well.

@andrewharvey
Copy link
Collaborator Author

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

@jwhazel
Copy link

jwhazel commented Aug 3, 2017

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();
});

@pathmapper
Copy link

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

@andrewharvey
Copy link
Collaborator Author

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. 🤔

@pathmapper
Copy link

pathmapper commented Sep 3, 2018

@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.

@andrewharvey
Copy link
Collaborator Author

@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.

@andrewharvey
Copy link
Collaborator Author

#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
Labels
Projects
None yet
Development

No branches or pull requests

6 participants