0

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

<script>
     $(document).ready(function() {
      $(pz).click(function() {
        L.mapbox.featureLayer('map.geojson').addTo(map)
    })
    });
</script>

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)

2 Answers 2

1

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

0

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

https://www.mapbox.com/mapbox.js/example/v1.0.0/layers/

1
  • 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 ... Apr 26, 2018 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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