My map has some stuff like points, lines, etc... and I want to remove some layers on the map when the user clicks on another part of the map, as follow:

   click: function(event) {

That removePolylines method, I wish to trigger it only when you click on the map, but not when you click on a line or point. How can I distinguish when click event is fired? I mean, I want to remove the lines when you click on nothing else but the map.


If you use jquery you can simply use the event.target. Official jquery documentation

Here is a working example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.