The attached script was created for the geojson file I created that works properly.

     $(document).ready(function() {
      $(pz).click(function() {

My question is how can I hide the displayed layer with the click feature?

I would like to ask you some help to create the script.

(I use mapbox.js not mapbox-gl.js)


Here is an official Mapbox examples which shows how to toggle layers using onclick:


  • Thank you, I try this example, but it does not work for something. The displayable layer can be retrieved from a dropdown / semantic menu ... it may be the problem ... – Balázs Nemes Apr 26 '18 at 11:25

My JavaScript is not that good, but instead of click look at https://api.jquery.com/toggle/

and then map.remove(); if needed depending on how $.toggle works.

PS: jquery could be added to your tags

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.