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)

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/

  • 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
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

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.