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

Circle drawn on the hit marker does not disappear when cancelling #293

Open
metametis opened this issue Feb 27, 2022 · 6 comments
Open

Circle drawn on the hit marker does not disappear when cancelling #293

metametis opened this issue Feb 27, 2022 · 6 comments

Comments

@metametis
Copy link

metametis commented Feb 27, 2022

Hi,
I use the marker.circle option. When I click on the cancel icon in the search box, the circle stays on the map, even with the option 'hideMarkerOnCollapse: true'.
However, when I make another research, the circle correctly disappears.
Is there a way to fix this ?
THank you,
Olivier

@hupe13
Copy link

hupe13 commented Jan 20, 2023

Maybe is it to late: hideMarkerOnCollapse does the job.
But there is an other problem with it. If I zoom the map, the circle appears again. To prevent this change

if(self._markerSearch) {

to

if(self._markerSearch && title != "") {

@metametis
Copy link
Author

Thank you. I fixed the problem already but to tell the truth, I don't remember how...
Olivier

@hupe13
Copy link

hupe13 commented Jan 20, 2023

I tested it again with my application, not that it is a special case. ...
I changed my code, now sometimes it works and sometimes it doesn't.
Sorry for trouble.
Edit: Solved, now it works.

@senavarreteh
Copy link

Hello. I have this same issue when i zoom, the circle just appears again. Couldn't fix the problem with what was suggested.
Is there any other way to fix this?

Im currently using leaflet 1.9.3 and leaflet-search 3.0.9

Thanks for the help.
Sergio.

@hupe13
Copy link

hupe13 commented Mar 11, 2023

I don't remember what I did specifically that the circle is now gone. Maybe this:

          markerSearchControl.on("search:cancel", function(e) {
            if (e.target.options.hideMarkerOnCollapse) {
              //console.log(e.target._map);
              e.target._map.removeLayer(this._markerSearch);
            }
          });

@senavarreteh
Copy link

senavarreteh commented Mar 13, 2023

Hello, thanks for answering!

Unfortunately those lines of code did not solve my problem.

I think I have found the source.

self._map.once('moveend zoomend', function(e) {

The "once" listener has 2 types: moveend and zoomend.

In previous versions of leaflet, if one or the other is executed, the listener is removed when the function finishes executing.

For the current version, both events must be executed to remove the listener. This causes the markers to be added again when zooming.

I don't know if this is intentional or a bug. For now I have solved the issue by removing the zoomend event from the listener.

You can try with this example and see two logs in your console (latest leaflet version).

map.once('moveend zoomend', function (e) { console.log(e.type); });

I hope this information is useful. And excuse my spelling mistakes.

Greetings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants