maplibre / maplibre-gl-geocoder

Geocoding for MapLibre
ISC License
53 stars 19 forks source link

Pin stays on the map when results of subsequent queries return #48

Open xinyuluo opened 2 years ago

xinyuluo commented 2 years ago

Hi! thanks for the amazing project. I have encountered what I think is a bug, because i think it should be irrelevant to my choice of geocoder (Nominatim).

To reproduce the bug:

  1. search for "NUS singapore" (I have a map of singapore), press enter.
  2. click on the one that says National University of Singapore from the dropdown list, it zooms in closer to the place;
  3. click enter again and the map zooms in even closer;
  4. search for the next query "NUH singapore" (do not clear manually clear search box), which has 2 results from the drop down. But when I zoom out the map, the pin for National University of Singapore is still there.

Please see attached screen recording for the reference.

Thank you!

https://user-images.githubusercontent.com/25223376/158390405-0ef0a3e5-9a54-490a-ad88-ef80b603d3c2.mp4

wipfli commented 2 years ago

Thanks for reporting. Can you share a stackblitz or something similar?

xinyuluo commented 2 years ago

@wipfli sure. demo is here: https://stackblitz.com/edit/web-platform-fszogw you will need a maptiler API key to access the basemap. Do you have one?

wipfli commented 2 years ago

Does the one for the MapLibre examples work? get_your_own_OpIi9ZULNHzrESv6T2vL from https://maplibre.org/maplibre-gl-js-docs/example/canvas-source/

xinyuluo commented 2 years ago

Yes it will work. I've just updated stackblitz.

wipfli commented 2 years ago

Cool, I can reproduce the bug you reported. Is there any chance that you can fix this behavior? I would be happy to review a pull request...

wipfli commented 2 years ago

Maybe one has to loop through features. Here is a different example where I made only one marker being highlighted: https://codesandbox.io/s/hopeful-elion-w04kb6

xinyuluo commented 2 years ago

How is the different example related to the bug? I will try to read code more closely when I have the bandwidth. If i can come up with a fix i will submit a PR

wipfli commented 2 years ago

Maybe it is not really related :S

wipfli commented 2 years ago

Cool, thanks @xinyuluo !

HarelM commented 1 month ago

The code after #118 should be fully typescript, which should help in solving these kind of cases, and if not, refactoring would be a lot easier. I see that there are promises returning from the geoApi, and there might be a race condition in this case, or a missing marker.remove call. It should be fairly easy to solve this I hope. Sorry for the late response...

HarelM commented 1 month ago

Can you reproduce this in the following example page: https://maplibre.org/maplibre-gl-js/docs/examples/geocoder/ I can't reproduce it...